Jump to:

3373 Posts in 998 Topics by 712 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: 2638 Views
  • CHD
    Avatar
    Community Member
    217 Posts

    Sort Order of front end control. Link to this post

    I have a table that displays a list of products uploaded through ModelAdmin.
    all is working well so far, but i cant seem to get the sort/order to work.

    My client needs to be able to manage the order the list as they require, first i hoped they could arrange it in the CSV file, then upload it and the order would be displayed on the front end. but that failed.
    then i tried using:

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

    this ALMOST works, but the order isn't consistent!
    I can't figure out why it's doing this?
    it seems like it only orders by the first character? so my results are something like:

    A
    AZ
    AA
    AT
    B
    BB
    BA

    does that make sense?

    ideally, i have a column in my CSV file called DisplayOrder, that the user can number all parts in the order he wishes them to appear and upload it. but again, it only seems to order by the first digit of the number, and there are over 700 products so its useless!

    can anyone help?

  • rob.s
    Avatar
    Community Member
    78 Posts

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

    Hi CHD,

    did you check the collation of the table and the collation of the (Title) fields ?

    Can you post the DDL of the table ?

    E.G.:

    CREATE TABLE `Product` (
    `ID` INT(11) NOT NULL AUTO_INCREMENT,
    ....
    PRIMARY KEY (`ID`)
    ) ENGINE=MYISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8

  • CHD
    Avatar
    Community Member
    217 Posts

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

    thanks for your reply.
    well actually my table is hardcoded and the field content is generated with a control. (i get a little confused when it comes to generating tables via functions!)

    heres my template code...this could be the problem:

    $ProductSearchForm

    <table id="ProductList" width="100%" border="0">
    <tr>
    <th width="35%">Title</th>
    <th width="">Part Number</th>
    <th width="">Serial Number</th>
    <th width="">Aircraft <br>
    Registration</th>
    <th width="">Type</th>
    <th width="">Aircraft <br>
    Serial</th>
    <th width="">Quantity </th>
    <th width="">Email us</th>
    </tr>
    <% if ProductList %>

    <!-- $ProductList.sort(Title)-->
    <% control ProductList %>
    <tr height="20px">
    <td>$Title</td>
    <td>$PartNumber</td>
       <td>$SerialNumber</td>
       <td>$AircraftRegistration</td>
       <td>$Type</td>
       <td>$AircraftSerial</td>
    <td>$DisplayOrder </td>
    <td><a href="mailto:was@aps-airparts.com?cc=info@worldaircraftsolutions.com.sg&subject=$PartNumber&nbsp;&ndash;&nbsp;$Title&">Email us</a> </td>
    </tr>

    <% end_control %>

    </table>

    <% else %>
        <p>Sorry, your search query did not return any results.</p>
       

    <% end_if %>

    <p id="ProductListPagination">
    <% if ProductList.MoreThanOnePage %>
    <% if ProductList.PrevLink %>
    <a href="$ProductList.PrevLink">&lt;&lt; Prev</a> |
    <% end_if %>

    <% control ProductList.Pages %>
    <% if CurrentBool %>
    <strong>$PageNum</strong>
    <% else %>
    <a href="$Link" title="Go to page $PageNum">$PageNum</a>
    <% end_if %>
    <% end_control %>

    <% if ProductList.NextLink %>
    | <a href="$ProductList.NextLink">Next &gt;&gt;</a>
    <% end_if %>
    <br>
    <br>

    <% end_if %>

    Total number of parts available: $ProductList.TotalItems

    </p>

  • rob.s
    Avatar
    Community Member
    78 Posts

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

    HI,

    I'm not shure what "....my table is hardcoded ..." means to me ....
    I guess that the collation of your table is not UTF-8 - that the sorting does not work properly

  • CHD
    Avatar
    Community Member
    217 Posts

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

    STUPID COMMENT - REMOVED TO SAVE FACE.

  • CHD
    Avatar
    Community Member
    217 Posts

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

    ha...just realised you were probably talking about my database table!
    so how do i set that to UTF-8?

  • CHD
    Avatar
    Community Member
    217 Posts

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

    just checked my phpMyAdmin:

    # Server version: 5.0.45
    # Protocol version: 10

    # MySQL charset: UTF-8 Unicode (utf8)
    # MySQL connection collation: utf8_general_ci

    --
    -- Table structure for table `Product`
    --

    CREATE TABLE IF NOT EXISTS `Product` (
    `ID` int(11) NOT NULL auto_increment,
    `ClassName` enum('Product') default 'Product',
    `Created` datetime default NULL,
    `LastEdited` datetime default NULL,
    `Title` varchar(50) default NULL,
    `PartNumber` varchar(50) default NULL,
    `SerialNumber` varchar(50) default NULL,
    `AircraftRegistration` varchar(50) default NULL,
    `Type` varchar(50) default NULL,
    `AircraftSerial` varchar(50) default NULL,
    `Quantity` varchar(50) default NULL,
    `Price` decimal(9,2) NOT NULL default '0.00',
    `Order` varchar(50) default NULL,
    `DisplayOrder` varchar(50) default NULL,
    PRIMARY KEY (`ID`),
    KEY `ClassName` (`ClassName`)
    ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=7158 ;

    guessing thats not the problem then?

  • rob.s
    Avatar
    Community Member
    78 Posts

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

    yep - looks good ....

    2638 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.