WebsiteBaker Community Forum

WebsiteBaker Support (2.12.x) => Modules => Topic started by: CodeALot on January 29, 2020, 06:06:12 PM

Title: ONEFORALL - Group sorting bug
Post by: CodeALot on January 29, 2020, 06:06:12 PM
If you use field type GROUP in OneForAll and SHOW GROUP HEADERS on, SORT BY GROUP on, the sorting goes wrong once you use more than 10 groups.
Sorting is done like:

1
10
11
2
3
4
5 --- etc.
 
Does anyone have a brilliant idea how to solve this?
Title: Re: ONEFORALL - Group sorting bug
Post by: dbs on January 29, 2020, 08:42:53 PM
Hi, try this. Find in view_overview.php the block.
Code: [Select]
// If a group field is defined order by group and position
Last line of this block is
Code: [Select]
          .'ORDER BY `f`.`value` '.$group_order.', `i`.`position` '.$position_order.$limit_sql;
Change it to
Code: [Select]
          .'ORDER BY LENGTH(`f`.`value`), `f`.`value` '.$group_order.', `i`.`position` '.$position_order.$limit_sql;

Only this is added:
LENGTH(`f`.`value`),
Hope it helps.
Title: Re: ONEFORALL - Group sorting bug
Post by: CodeALot on January 29, 2020, 10:55:46 PM
You're the best. That solved it. MANY thanks!
Title: Re: ONEFORALL - Group sorting bug
Post by: DarkViper on January 29, 2020, 11:01:33 PM
If it is certain that 'f.value' contains a number (integer), it is easier to evaluate this value in the sorting as a number.
This can be achieved with the SQL function CAST(expression AS datatype)'.
Code: [Select]
  .'ORDER BY CAST(`f`.`value` AS UNSIGNED) '.$group_order.', `i`.`position` '.$position_order.$limit_sql;
see:
https://dev.mysql.com/doc/refman/5.7/en/cast-functions.html#function_cast (function cast and description of types in function convert)