Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#1220 SMART config order should sort keys in DESC order too

invalid
nobody
None
5
2013-06-11
2010-03-19
Ruben Barkow
No

if i set
/**
* default for 'ORDER BY' clause (valid values are 'ASC', 'DESC' or 'SMART' -ie
* descending order for fields of type TIME, DATE, DATETIME & TIMESTAMP,
* ascending order else-)
*/
$cfg['Order'] = 'SMART';

it only counts for time and date fields, but the most clicks i have to do is when i go into a database table is to click two times on the "id" field

it would be nice to have SMART to deal with fields that are numeric in DESC order too.
or just fields with the fieldnames "id", "index", "idx" and "key"

Discussion

1 2 > >> (Page 1 of 2)
  • Ruben Barkow
    Ruben Barkow
    2010-03-19

    just edit line 818 in display_tbl.lib.php:
    // use DESC order for date and time fields and fields with the name "id", "index", "idx" or "key"
    $sort_order .= (preg_match('@time|date@i', $fields_meta[$i]->type) || in_array(strtolower($fields_meta[$i]->name),array("id", "index", "idx", "key"))) ? 'DESC' : 'ASC';

     
  • Ruben Barkow
    Ruben Barkow
    2010-03-19

    or better if the ending of the fieldname is one of these:
    "id", "index", "idx", "key", "fkey", "foreignkey"
    this would be the patch:

    if ($GLOBALS['cfg']['Order'] === 'SMART') {
    // use DESC order for date and time fields and fields with the name "id", "index", "idx" or "key" or that end with these
    $indexkeys=array("id", "index", "idx", "key", "fkey", "foreignkey");
    $sort_order .= (preg_match('@time|date@i', $fields_meta[$i]->type)
    || preg_match("/(_".implode("|_",$indexkeys).')$/', $fields_meta[$i]->name)
    || in_array(strtolower($fields_meta[$i]->name), $indexkeys)) ? 'DESC' : 'ASC';
    }

     
  • Ruben Barkow
    Ruben Barkow
    2010-03-19

     
    Attachments
  • Ruben Barkow
    Ruben Barkow
    2010-03-19

    also it would help even more, if there could ba an option in config, that all tables have an
    ORDER BY `id` DESC
    by default if the field "id" exists

    this would save a lot of time, cause in development, you usually want to see the latest entry first

     
  • Michal Čihař
    Michal Čihař
    2010-04-05

    Determining sort order by field name sounds like a bad idea. I have already seen lot of production system where "id" field was actually a string and I guess it is even more common for "key".

     
  • Ruben Barkow
    Ruben Barkow
    2010-04-05

    so the sort order should only be descending, if the field is numeric

     
  • Michal Čihař
    Michal Čihař
    2010-04-06

    Yes, it would probably make more sense, However I'm not sure if majority of people will like this behavior.

     
  • Ruben Barkow
    Ruben Barkow
    2010-04-06

    the question is: do more users look for the greatest number or the smallest?
    maybe it would be SMART to sort ALL numeric values descending by default?

    i personally cannot remember any situation where i was looking for the smallest Index ;)

    another thing:
    if this is implemented, i think the links that are sorted descending should have a different color from those that are sorted ascending

     
  • Ruben Barkow
    Ruben Barkow
    2010-09-30

    i would call the new order format option
    $cfg['Order'] = 'SMARTER'

     
  • Marc Delisle
    Marc Delisle
    2012-03-05

    Now that version 3.5 remembers the last sort order, I guess we don't need this RFE.

     
1 2 > >> (Page 1 of 2)