How can I set the order in the Data Displayer?

The ChronoForms DB Multi-Record Loader action has a built in data displayer tab that creates a neat table for the records selected. This FAQ shows you how to set the order of the records listed.
On the Data Displayer tab of the DB Multi-Record Loader action is an Order Fields box. If you add a column name e.g. id, or a comma separated list (with no spaces) of column names  e.g. id,title here then the Column Headers of your listing will become clickable so that the columns can be sorted.
However this does not set a default order for the initial listing. You can do this by adding a Custom Code action before the DB Multi-Record Loader action and adding code like this
<?php
if ( !isset($form->data['order']) || !$form->data['order'] ) {
  $form->data['order'] = 'id';
}
?>
You'll need to replace highlighted id with the name of the table column that you want to sort by.
By default this will sort in Ascending order e.g. 1, 2, 3, . . . if you need to sort in Descending order e.g. 99, 98, 97, . . . then use this version of the code 
<?php
if ( !isset($form->data['order']) || !$form->data['order'] ) {
  $form->data['order'] = 'id';
  if ( !isset($form->data['direction']) || !$form->data['direction'] ) {
    $form->data['direction'] = 'DESC';
  }
}
?>
 

Comments:

You need to login to be able to post a comment.