mirror of
https://github.com/UndefinedOffset/SortableGridField.git
synced 2024-10-22 17:05:38 +02:00
Added ModelAdmin Example
Updated examples to say they are written with 3.0.x in mind and public statics should be private in 3.1.x
This commit is contained in:
parent
1e963bfef1
commit
53eef90c97
@ -35,6 +35,7 @@ To move an item to another page drag the row over the respective page button and
|
||||
#### Full code Examples
|
||||
* [has_many relationship] (https://github.com/UndefinedOffset/SortableGridField/blob/master/docs/HasManyExample.md)
|
||||
* [many_many relationship] (https://github.com/UndefinedOffset/SortableGridField/blob/master/docs/ManyManyExample.md)
|
||||
* [ModelAdmin implementation] (https://github.com/UndefinedOffset/SortableGridField/blob/master/docs/ModelAdminExample.md)
|
||||
|
||||
#### Events
|
||||
GridFieldSortableRows provides 4 "events" onBeforeGridFieldRowSort(), onAfterGridFieldRowSort(), onBeforeGridFieldPageSort() and onAfterGridFieldPageSort(). These "events" are passed a clone of the DataList used in GridFieldSortableRows, in the case of page sorting this list has a limit that shows you the current page plus/minus one object. For GridFieldSortableRows that are on ModelAdmin decendents these events are called on the ModelAdmin if they do not have a owner DataObject, if you are using GridFieldSortableRows on a GridField for a DataObject's relationship the events are called on that DataObject.
|
||||
|
@ -1,5 +1,6 @@
|
||||
has_many Example
|
||||
=================
|
||||
Please note this example is written with 3.0.x in mind, if you are using 3.1.x make sure you scope all static properties to private not public.
|
||||
```php
|
||||
/*** TestPage.php ***/
|
||||
class TestPage extends Page {
|
||||
|
@ -1,5 +1,6 @@
|
||||
many_many Example
|
||||
=================
|
||||
Please note this example is written with 3.0.x in mind, if you are using 3.1.x make sure you scope all static properties to private not public.
|
||||
```php
|
||||
/*** TestPage.php ***/
|
||||
class TestPage extends Page {
|
||||
|
38
docs/ModelAdminExample.md
Normal file
38
docs/ModelAdminExample.md
Normal file
@ -0,0 +1,38 @@
|
||||
ModelAdmin implementation Example
|
||||
=================
|
||||
Please note this example is written with 3.0.x in mind, if you are using 3.1.x make sure you scope all static properties to private not public.
|
||||
```php
|
||||
/**** MyModelAdmin.php ****/
|
||||
class MyModelAdmin extends ModelAdmin {
|
||||
public static $menu_title='My Model Admin';
|
||||
public static $url_segment='my-model-admin';
|
||||
|
||||
public static $managed_models=array(
|
||||
'MATestObject'
|
||||
);
|
||||
|
||||
public function getEditForm($id = null, $fields = null) {
|
||||
$form=parent::getEditForm($id, $fields);
|
||||
|
||||
//This check is simply to ensure you are on the managed model you want adjust accordingly
|
||||
if($this->modelClass=='MATestObject' && $gridField=$form->Fields()->dataFieldByName($this->sanitiseClassName($this->modelClass))) {
|
||||
//This is just a precaution to ensure we got a GridField from dataFieldByName() which you should have
|
||||
if($gridField instanceof GridField) {
|
||||
$gridField->getConfig()->addComponent(new GridFieldSortableRows('SortOrder'));
|
||||
}
|
||||
}
|
||||
|
||||
return $form;
|
||||
}
|
||||
}
|
||||
|
||||
/**** MATestObject.php ****/
|
||||
class MATestObject extends DataObject {
|
||||
public static $db=array(
|
||||
'Title'=>'Varchar',
|
||||
'SortOrder'=>'Int'
|
||||
);
|
||||
|
||||
public static $default_sort='SortOrder';
|
||||
}
|
||||
```
|
Loading…
Reference in New Issue
Block a user