Order of records

4 posts by 2 authors in: Forums > CMS Builder
Last Post: July 26, 2013   (RSS)

By Kittybiccy - July 25, 2013

How can I change how the order of records are displayed? I would like the newest first to automatically be at the to of the list (and page 1 where lots of records!) whereas at the moment it goes to the end. I've tried to adjust this in my section editor/sorting but it comes up with errors.

Thanks, Hannah

By gregThomas - July 25, 2013

Hi Hannah, 

Are you using a getRecords function to retrieve your records? If so you could use an orderBy key in it to ensure that the newest records are displayed first:

  // load records from 'blog'
  list($blogRecords, $blogMetaData) = getRecords(array(
    'tableName'   => 'blog',
    'loadUploads' => true,
    'allowSearch' => false,
    'orderBy'     => 'createdDate DESC'
  ));

This is just example code, so you'll have to make a few changes to get it working with your site. 

So the orderBy key would cause the records to be sorted by createdDate in decening order, which will display the newest records first.

Let me know if you have any questions.

Thanks

Greg

Greg Thomas







PHP Programmer - interactivetools.com

By gregThomas - July 26, 2013

Hi,

To do this you'll have to remove the dragSortOrderBy field, and then sort the current blog records by creation date. To do this log into CMS Builder, then go to the section editors menu. Click the modify link for the section in question, this will take you to the section modification page. To be able to sort a list by date you need to first remove the dragSortOrder field. To do this click the erase link in the list of fields on the sections modification page. Once this has been done, click the sorting tab at the top of the section modification screen, in this tab you'll see an input called Order By, change this too:

createdDate DESC 

Now click the Save Details link and everything should be set up. When you go back to section you should find that all of the links are sorted in date order.

This change will also be applied to any getRecords lists on the front of your site as well.

Let me know if you have any questions.

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com