Page 1 of 1

Ordering a single table by a numeric field within it.

PostPosted: Fri Feb 25, 2011 10:27 am
by neotrode
Hello Shannah.

The metafields:order function seems like a great feature, however it only works on relationships. Are there any plans to implement a similar feature for a single table?

For example. I have a table called "sections". In it are the standard "id", "section_name", "description" fields. But I also add a field at the end called "display_order". The Display Order field is a simple INT field in which a numeric value dictates the order of the data. This way I can use a simple query in my website like "SELECT * FROM sections ORDER BY display_order ASC". This is because the display order is not necessarily by any sortable order other than user preference.

Are there plans to make such a tool like metafields:order for single unrelated tables?

-Frank

Re: Ordering a single table by a numeric field within it.

PostPosted: Sat Feb 26, 2011 1:11 pm
by shannah
It wouldn't be hard to implement so I can see it being added to a future release.

In the mean time, you could accomplish a default sort by adding the following to the beforeHandleRequest() method of the application delegate class.

Code: Select all
function beforeHandleRequest(){
    $query =& Dataface_Application::getInstance()->getQuery();
    if( !$_POST and  $query['-table'] == 'my_table' and !isset($query['-sort']) ){
        $query['-sort'] = 'display_order asc';
    }
}