21489 Posts in 5783 Topics by 2622 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 382 Views |
-
Custom sort of DataObjects

8 August 2012 at 9:26pm
Hey there!
How can I custom sort DataObjects - means how to sort them independent from it's columns. This was possible with the DataObject Manager Module in SS 2.x and it was great!
Thanks. Mario
-
Re: Custom sort of DataObjects

9 August 2012 at 3:53am
I think it's going to be introduced to the core at a later date, but at the moment you need to install this module:
-
Re: Custom sort of DataObjects

9 August 2012 at 4:42am Last edited: 10 August 2012 7:43pm
Hi:
That module works great .. It took me sometime to get it working so here few things that may save you alot of time :
Example for a basic Gallery module = Gallery has_many GalleryImages
** GalleryImage.php
- Make sure you add field for SortID
Code to use :
// to change the default sorting to the new SortID
public static $default_sort = 'SortID Asc';
// To change the Default Value if SortID to LastSortID+1 , basic auto sort
function onBeforeWrite() {
parent::onBeforeWrite();
if (!$this->SortID) {
return $this->SortID = $this->getNextSortID();
}
}public function getNextSortID() {
return $this->SGallery()->Images()->Last()->SortID + 1;
}** Gallery.php
function getCMSFields() {
$fields = parent::getCMSFields();
//......
$gridFieldConfig = GridFieldConfig_RelationEditor::create();
$gridFieldConfig->addComponents(
new GridFieldSortableRows("SortID")
);
//....
}
| 382 Views | ||
|
Page:
1
|
Go to Top |



