3063 Posts in 864 Topics by 646 members
| Go to End | ||
| Author | Topic: | 2194 Views |
-
Re: Sort Order of front end control.

1 September 2010 at 2:16am Last edited: 1 September 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 pagethis 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?!?
-
Re: Sort Order of front end control.

1 September 2010 at 2:50am Last edited: 1 September 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 endand
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
| 2194 Views | ||
| Go to Top |

