mirror of
https://github.com/symbiote/silverstripe-gridfieldextensions.git
synced 2024-10-22 15:05:39 +00:00
parent
5eec0f70b4
commit
796bd0ad68
@ -79,3 +79,21 @@ $grid->getConfig()->addComponent(new GridFieldOrderableRows());
|
|||||||
// Specifying the sort field.
|
// Specifying the sort field.
|
||||||
$grid->getConfig()->addComponent(new GridFieldOrderableRows('SortField'));
|
$grid->getConfig()->addComponent(new GridFieldOrderableRows('SortField'));
|
||||||
```
|
```
|
||||||
|
|
||||||
|
By default, when you create a new item, it is created with a sort order of "0" - that is, it is added
|
||||||
|
to the start of the list. The sort order is only set for the first time when the user reorders the items.
|
||||||
|
If you wish to append newly created items to the end of the list, use an `onBeforeWrite` hook like:
|
||||||
|
|
||||||
|
```php
|
||||||
|
class Item extends DataObject {
|
||||||
|
private static $db = array('Sort' => 'Int');
|
||||||
|
|
||||||
|
protected function onBeforeWrite() {
|
||||||
|
if (!$this->Sort) {
|
||||||
|
$this->Sort = Item::get()->max('Sort') + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
parent::onBeforeWrite();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
Loading…
x
Reference in New Issue
Block a user