5415 Posts in 1651 Topics by 1188 members
|Go to End|
28 January 2010 at 8:51am
We have a page People.php with children of the type Person.php displaying names, positions etc (so Person.php has fields Name and Position). By design they are sorted by Name.
How to make "headers" Name and Position clickable so clicking on "Position" sorting would be on Position, and only then by Name and vv?
I know how to do it in php/sql, but in frames of SilverStripe?
Thank you. Victor
29 January 2010 at 7:14am
If you use the DataObjectManger module to manage the Person DataObject it does it out of the box
29 January 2010 at 11:38pm
DataObjectManager does it for editor of CMS, I am talking about viewer
30 January 2010 at 2:59am
There are a lot of table sorting plugin available for jQuery if you need to handle it in the front then. If you want to do it in the front end with PHP the best way is to create a function that either checks for a URL variable or uses the action/id method and returns the dataobject. You can then have the table heading either call this function or reload the page with the correct URL variable.
I do something like this on Products that have multiple colors
$colorSelect = $_GET['color'];
return DataObject::get("Color", "StripedColorName='".$colorSelect."' AND ColorProductID = ".$this->ID);
The colo links on the page just reload the page with ?color=pink tacked on the end. Then in my template I just do a check against showColor and if its there I use a showColor control to render the data. In you case it would even be easier since it the same data just in a different order.
Silverstripe will needs to let you call the Sort() function form the template as it does for GroupBy().
30 January 2010 at 3:57am
Could you recommend a sorting plugin (js) and how to install it and to hook to the page?
30 January 2010 at 4:14am
Just download jquery from http://jQuery.com (or call it directly from google in Page.php) and the plugin http://tablesorter.com/ Call both js files from your template or page class and follow the instruction on the tablesorter plugin, its pretty easy just one line of code to implement it.
|Go to Top|