Author Topic: ONEFORALL - Group sorting bug  (Read 226 times)

Offline CodeALot

  • Posts: 488
  • Gender: Male
ONEFORALL - Group sorting bug
« 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?

Offline dbs

  • Betatester
  • **
  • Posts: 8367
  • Gender: Male
  • tioz4ever
    • WebsiteBaker - jQuery-Plugins - Module - Droplets - Tests
Re: ONEFORALL - Group sorting bug
« Reply #1 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.

Offline CodeALot

  • Posts: 488
  • Gender: Male
Re: ONEFORALL - Group sorting bug
« Reply #2 on: January 29, 2020, 10:55:46 PM »
You're the best. That solved it. MANY thanks!

Offline DarkViper

  • Forum administrator
  • *****
  • Posts: 3053
  • Gender: Female
Re: ONEFORALL - Group sorting bug
« Reply #3 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)
Der blaue Planet - er ist nicht unser Eigentum - wir haben ihn nur von unseren Nachkommen geliehen

"You have to take the men as they are… but you can not leave them like that !" :-P
Das tägliche Stoßgebet: Oh Herr, wirf Hirn vom Himmel !

 

postern-length