Do an SVN update, and try adding in your config:
SortableDataObject::set_sort_dir("DESC");
This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.
Please use forum.silverstripe.org for any new questions
(announcement).
The forum archive will stick around, but will be read only.
You can also use our Slack channel
or StackOverflow to ask for help.
Check out our community overview for more options to contribute.
Discuss the DataObjectManager module, and the related ImageGallery module.
Moderators: martimiz, UncleCheese, Sean, Ed, biapar, Willr, Ingo, swaiba
Do an SVN update, and try adding in your config:
SortableDataObject::set_sort_dir("DESC");
What's the correct argument to place my sort order if I'm using an IDOM?
I played around with it the other night with no luck. I'm trying to understand the whole DOM a bit more.
I don't have SVN setup so it's a bit of a hassle to update DEV then push out to PROD and honestly, I'm a bit reluctant to do it only because I'm new to SS and have spent more time debugging than I have coding.
I'm loving the DOM so far now that I've got a grasp of it, but is there some solid documentation for it anywhere?
So far, it's been a process of trial and error and searching the forums for solutions.
UncleCheese
I download
http://carlinowebdesign.svn.beanstalkapp.com/modules/trunk/dataobject_manager/code/SortableDataObject.php
and
SortableDataObject::set_sort_dir("DESC"); - set sort for FrontEnd, but it not set order for Admin zone
How can I make so that when add a new item it is assigned SortOrder=0, and the rest was appropriated by the SortOrder +1.
Or what would be in the admin area of sorting was also SortOrder DESC
Did you download the file directly from your browser? You shouldn't be doing that. You need to checkout the entire package with SVN.
SortableDataObject works in conjunction with DataObjectManager, and works like this:
You register a class with SortableDataObject::add_sortable_class("MyClass")
This does the following:
1) Forces new objects to get a SortOrder value of (total records) + 1;
2) Allows drag and drop ordering in DOM
3) Forces default sort order of SortOrder (ASC/DESC) on the frontend.
Seems like these issue were never really fixed...
The problem is that the DataObjectManager can't do 'descending' columns, (clicking the titles gets a descending arrow but the results always count up) - or at least it can't when the list is sortable
So we have go about it differently. Keep the SortOrder counting up, but add your new item in at the start of the list, not the end.
This has to be done via onAfterWrite.
Note, I'm not using any write() commands in the function, becuase that invokes the 'onAfterWrite' function again, causing a loop.
Basically, we loop through all the items, increase their sort order by one, and set our new item to '0' to sit at the start of the list.
private $firstWrite = false;
function onBeforeWrite() {
parent::onBeforeWrite();
if (!$this->ID) $this->firstWrite = true;
}
function onAfterWrite() {
if ($this->firstWrite) {
$ProductPageID = $this->ProductPageID;
if ($records = DataObject::get('Item', "`ProductPageID` = '$ProductPageID' ", 'SortOrder ASC')) {
foreach ($records as $record) {
$origSort = $record->SortOrder;
if ($origSort == '') { $origSort = 0;}
$NewSortOrder = $record->SortOrder + 1;
$itemID = $record->ID;
//$record->write();
mysql_query("UPDATE `Item` SET `SortOrder`='$NewSortOrder' WHERE `ID`='$itemID' ");
}
}
$itemID = $this->ID;
mysql_query("UPDATE `Item` SET `SortOrder`='0' WHERE `ID`='$itemID' ");
}
return parent::onAfterWrite();
}