Ordering a single table by a numeric field within it.

A place for users and developers of the Xataface to discuss and receive support.

Ordering a single table by a numeric field within it.

Postby neotrode » Fri Feb 25, 2011 10:27 am

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
neotrode
 
Posts: 26
Joined: Mon Dec 20, 2010 11:08 am

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

Postby shannah » Sat Feb 26, 2011 1:11 pm

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';
    }
}
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 20 guests

cron
Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved