Silverstripe ModelAdmin 拖放可排序
Silverstripe ModelAdmin drag and drop Sortable
我想让我的 ModelAdmin GridField 可以通过拖放进行排序。我尝试添加此代码:
$gridFieldName = 'Destributors';
$gridField = $form->Fields()->fieldByName($gridFieldName);
if ($gridField) {
$gridField->getConfig()->addComponent(new GridFieldFilterHeader(),new GridFieldSortableRows('SortOrder'));
}
但是好像不行。关于如何实施它的任何想法?
任何帮助将不胜感激
这是我在 SS3 项目中使用的代码。您应该能够轻松地将其更新为 SS4。
<?php
class MealsModelAdmin extends ModelAdmin {
private static $managed_models = array(
'MealAttribute',
'MenuCategory'
);
private static $url_segment = 'configuration';
private static $menu_title = 'Configuration';
public function getEditForm($id = null, $fields = null){
$form = parent::getEditForm($id, $fields);
$model = singleton($this->modelClass);
/** add sorting if we have a field for... */
if (class_exists('GridFieldOrderableRows')
&& $model->hasField('SortOrder')
&& $gridField=$form->Fields()->dataFieldByName($this->sanitiseClassName($this->modelClass))) {
if($gridField instanceof GridField) {
$gridField->getConfig()->addComponent(new GridFieldOrderableRows('SortOrder'));
}
}
return $form;
}
}
我想让我的 ModelAdmin GridField 可以通过拖放进行排序。我尝试添加此代码:
$gridFieldName = 'Destributors';
$gridField = $form->Fields()->fieldByName($gridFieldName);
if ($gridField) {
$gridField->getConfig()->addComponent(new GridFieldFilterHeader(),new GridFieldSortableRows('SortOrder'));
}
但是好像不行。关于如何实施它的任何想法?
任何帮助将不胜感激
这是我在 SS3 项目中使用的代码。您应该能够轻松地将其更新为 SS4。
<?php
class MealsModelAdmin extends ModelAdmin {
private static $managed_models = array(
'MealAttribute',
'MenuCategory'
);
private static $url_segment = 'configuration';
private static $menu_title = 'Configuration';
public function getEditForm($id = null, $fields = null){
$form = parent::getEditForm($id, $fields);
$model = singleton($this->modelClass);
/** add sorting if we have a field for... */
if (class_exists('GridFieldOrderableRows')
&& $model->hasField('SortOrder')
&& $gridField=$form->Fields()->dataFieldByName($this->sanitiseClassName($this->modelClass))) {
if($gridField instanceof GridField) {
$gridField->getConfig()->addComponent(new GridFieldOrderableRows('SortOrder'));
}
}
return $form;
}
}