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.

Data Model Questions /

Sort Order of front end control.


Go to End
Reply


10 Posts   2948 Views

Avatar
CHD

Community Member, 218 Posts

30 August 2010 at 1:52am

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?

Avatar
rob.s

Community Member, 78 Posts

1 September 2010 at 12:26am

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

Avatar
CHD

Community Member, 218 Posts

1 September 2010 at 12:41am

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>

Avatar
rob.s

Community Member, 78 Posts

1 September 2010 at 12:55am

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

Avatar
CHD

Community Member, 218 Posts

1 September 2010 at 1:11am

Edited: 01/09/2010 1:57am

STUPID COMMENT - REMOVED TO SAVE FACE.

Avatar
CHD

Community Member, 218 Posts

1 September 2010 at 1:47am

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

Avatar
CHD

Community Member, 218 Posts

1 September 2010 at 1:50am

Edited: 01/09/2010 1:55am

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?

Avatar
rob.s

Community Member, 78 Posts

1 September 2010 at 2:05am

yep - looks good ....

Go to Top