New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sort ModelAdmin GridFields #6
Comments
I think what your doing to get model admin to do what you want is very close to what I would have done, though though instead of replacing getEditField() I would have overridden it and added to the GridField's config. (Hint the GridField's name is the model class). Thanks for the bug report, I've got the issue fixed now in master. So you should be good to go, let me know if it still causes issues. To answer your last comment about how does the sort order get incremented when a new object is added. This is done the next time the grid field is displayed automatically via the fixSortColumn() method. So there is no need for a DataExtension of the DataObject. This way the class is more portable and could be merged into the core of SS like was intended but the core team didn't get a chance to review and merge in time though Ingo did guide all of the dev for this class. |
it works like a charm :-) |
In case anybody wants this... I overrode getEditForm to retain any existing components and config instead of creating the gridField from scratch. function getEditForm($id = null, $fields = null) {
$form = parent::getEditForm($id,$fields);
$class = $this->modelClass;
if($class::$default_sort != null) {
$listField = $form->Fields()->fieldByName($this->modelClass);
$listFieldConfig = $listField->getConfig()->addComponent(new GridFieldSortableRows($class::$default_sort));
$listField->setConfig($listFieldConfig);
$form->setFields(new FieldList($listField));
}
return $form;
} Add this function when you extend ModelAdmin to get sortable DataObject lists (that aren't part of has_many / any_many relationship). |
Hi, i would be cool when your Module supports his functionality for ModelAdmin generated GridFields.
I get it work after adding a few lines of code into the getEditForm Method by Overlading the ModelAdmin:
....
$class = $this->modelClass;
if($class::$default_sort != null) {
$conf=GridFieldConfig_RelationEditor::create(10);
$conf->addComponent(new GridFieldSortableRows($class::$default_sort));
$listField->setConfig($conf);
}
.....
}
But i get this Notice when i dragged&dropped some Row:
[19-Aug-2012 00:04:30] Notice at SortableGridField/code/forms/GridFieldSortableRows.php line 214: Object of class GridState_Data could not be converted to int (http://fritz-mueller-gmbh.dev/admin/contactadmin/Devision/EditForm/field/Devision)
I fixed it by adding this:
if ($paginator = $gridField->getConfig()->getComponentsByType('GridFieldPaginator')->First()) { $pageState = $gridField->State->GridFieldPaginator; $currentPage = $pageState->currentPage; if(is_int($currentPage)) { if($pageState->currentPage && $pageState->currentPage>1) { $pageOffset = $paginator->getItemsPerPage() \* ($pageState->currentPage - 1); } } }
I think its better to extend the ModelAdmin instead of my overloading method.
How do you increase the 'SortOrder" Field when somebody add new Records?
Maybe you forget on the TestDataObject something like this? :
In your Example?
Maybe to decorate the obBeforeWrite Method of the DataObject like this
should be nice
The text was updated successfully, but these errors were encountered: