Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Data Model Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Sort Order of front end control.


Go to End


10 Posts   5139 Views

Avatar
CHD

Community Member, 219 Posts

1 September 2010 at 2:16am

Edited: 01/09/2010 2:29am

hmmm this is confusing!

lets recap:

i've attached my:
Catalogue.ss template
Product.php class for the dataobject
Catalogue.php class for the page

this is the code that limits the results and SHOULD sort them into DEC by displayOrder (which are numbers from 1- 715)

class Catalogue extends Page {
      public function ProductList ($filter = null){
if(!isset($_REQUEST['start'])) $_REQUEST['start'] = 0;
$limit = $_REQUEST['start'].",25";
$order = 'DisplayOrder DESC'; 
return DataObject::get('Product', $filter, $order, null, $limit);
}

but it doesn't...there is SOME order to it:
http://www.worldaircraftsolutions.com.sg/catalogue/?flush=1&start=0
but its not right!

it looks like it is only sorting the current page. so 25 results at a time. every page is sorted by displayOrder but not the whole catalogue... so i guess the problem lies in my $limit?

EDIT:
just took ut the limit and the sort order is fine... so its limiting the results before sorting them into order i guess?
any ideas?

UPDATE:
i took out this line: $ProductList.sort(DisplayOrder)
from my template and the order stopped working completely! so this line of code in my php file: $order = 'DisplayOrder DESC'; wasnt working.
i took out the word DESC and now it orders the items...but only by first character, not the whole number!

can anybody help with this?!?

Avatar
CHD

Community Member, 219 Posts

1 September 2010 at 2:50am

Edited: 01/09/2010 2:50am

DONE IT!!!!
i tried "natural sort" to show results as a human would expect (NATSORT) but that had no effect.

So i changed my field type to integar (INT) instead and it works perfectly!!!

final code:

class Catalogue extends Page {
      public function ProductList ($filter = null){
if(!isset($_REQUEST['start'])) $_REQUEST['start'] = 0;
$limit = $_REQUEST['start'].",25";
$sort = 'DisplayOrder ASC'; 
return DataObject::get('Product', $filter, $sort, null, $limit);
}

in catalogue.php for front end

and

class Product extends DataObject {
 
   static $db = array(
      'Title' => 'Varchar',
      'PartNumber' => 'Varchar',
      'SerialNumber' => 'Varchar',
	  'AircraftRegistration' => 'Varchar',
	  'Type' => 'Varchar',
	  'AircraftSerial' => 'Varchar',
	  'Quantity' => 'Varchar', 
	  'DisplayOrder' => 'Int'
   );

in product.php

Go to Top