Jump to:

3460 Posts in 1064 Topics by 739 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Sort Order of front end control.

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

Page: 1 2
Go to End
Author Topic: 2843 Views
  • CHD
    Avatar
    Community Member
    218 Posts

    Re: Sort Order of front end control. Link to this post

    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?!?

  • CHD
    Avatar
    Community Member
    218 Posts

    Re: Sort Order of front end control. Link to this post

    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

    2843 Views
Page: 1 2
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.