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


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"


  • 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

    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.

  • Marc Delisle

    Marc Delisle - 2012-03-05
    • status: open --> closed-rejected
  • Ruben Barkow

    Ruben Barkow - 2012-03-09

    i think this shouldn't be closed.

    it is still the same: the first time, you go into a table, you want to have it sorted "SMARTER"

    if we don't have this feature, you would still have to select the needed sort order for every of your (maybe hundreds of) tables

    you really nearly never want to see the oldest entry on top when you visit a table the first time.
    the newest entry should be default.

  • Marc Delisle

    Marc Delisle - 2012-03-09

    Michal and me don't find that the majority of users would like this sort behavior, this is why the request is closed.

  • Michal Čihař

    Michal Čihař - 2013-06-11
    • Status: closed-rejected --> invalid

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.

No, thanks