Page 1 of 1

Filter & sort by field on tables on a table by table bas

PostPosted: Fri Feb 27, 2009 4:33 am
by tomhousley
Dear all,

I have a few tables, and i want to have them have a default sort when each table is seen in browse and for some to be filtered

Eg:

tbl_jobs needs to sort by job_id descending
tbl_organisations needs to sort by org_name ascending and filtered where org_showindatabase = 1

Any help would be appreciated.

By the way, Xataface has to be the coolest tool! I have searched and tried to make use of many GPL online database / form builders and without a doubt this is the most powerful coupled with ease of use tool I've used.

Many thanks, Tom

PostPosted: Fri Feb 27, 2009 8:35 am
by shannah
Hi Tom,

Currently there's no configuration parameter for default sort (that would be a nice feature for future). What I generally do when this requirement comes up is to this by php. In the beforeHandleRequest() method of the ApplicationDelegate class:

Code: Select all
function beforeHandleRequest(){
    $app =& Dataface_Application::getInstance();
    $query =& $app->getQuery();
    if ( $query['-table'] == 'tbl_jobs' and !@$query['-sort'] and !$_POST ){
        $query['-sort'] = 'job_id desc';
    }

    ... etc...
}


So you'll notice that I check on a couple of things here:
1. Is the current request for the table.
2. Has the sort been set yet (we don't want to override explicitly set sorts.
3. Is this a POST. Best not to mess with POST requests.

-Steve