我在多对多关系中添加了一个额外的Data
字段,而且我不知道如何进行编辑。
功能
private static $belongs_many_many = [
'Model' => Model::class
];
模型
private static $many_many = [
'Features' => Feature::class,
];
private static $many_many_extraFields = [
'Features' => [
'SortOrder' => 'Int',
'Data' => 'Varchar'
]
];
-- / --
$features = Feature::get();
$searchFeaturesButton = new GridFieldAddExistingSearchButton();
$searchFeaturesButton->setSearchList($features);
$featureConfig = GridFieldConfig_RelationEditor::create();
$featureConfig->removeComponentsByType([GridFieldAddExistingAutocompleter::class, GridFieldEditButton::class, GridFieldAddNewButton::class]);
$featureConfig->addComponent(new GridFieldOrderableRows());
$featureConfig->addComponent($searchFeaturesButton);
$featureGrid = GridField::create('Features', 'Features', $this->Features(), $featureConfig);
$field->addFieldToTab('Root.Main', $featureGrid);
-- / --
如何在Data
的GridField中将其视为一列并对其进行编辑?
排序由GridfieldOrderableRows()
管理
答案 0 :(得分:1)
在SilverStripe 3和4中,我们可以使用SilverStripe GridField Extensions模块GridFieldEditableColumns feature编辑many_many_extraFields
数据。
以下是如何执行此操作的示例:
// Features field existing search button
$featuresGridFieldSearchButton = new GridFieldAddExistingSearchButton();
$featuresGridFieldSearchButton->setSearchList(Feature::get());
// Features field editable columns
$featuresGridFieldEditableColumns = new GridFieldEditableColumns();
$featuresGridFieldEditableColumns->setDisplayFields([
'Title' => [
'title' => 'Title',
'field' => ReadonlyField::class,
],
'Data' => [
'title' => 'Data',
'field' => TextField::class,
],
]);
// Features field config including base GridFieldConfig_RelationEditor components, custom search button, editable columns and orderable rows
$featuresGridFieldConfig = GridFieldConfig::create();
$featuresGridFieldConfig->addComponent(new GridFieldButtonRow('before'));
$featuresGridFieldConfig->addComponent($featuresGridFieldSearchButton);
$featuresGridFieldConfig->addComponent(new GridFieldToolbarHeader());
$featuresGridFieldConfig->addComponent(new GridFieldTitleHeader());
$featuresGridFieldConfig->addComponent($featuresGridFieldEditableColumns);
$featuresGridFieldConfig->addComponent(new GridFieldDeleteAction(true));
$featuresGridFieldConfig->addComponent(new GridFieldOrderableRows());
$featuresGridFieldConfig->addComponent(new GridFieldPageCount('toolbar-header-right'));
$featuresGridFieldConfig->addComponent(new GridFieldPaginator());
$featuresGridFieldConfig->addComponent(new GridFieldDetailForm());
$featuresGridField = GridField::create(
'Features',
'Features',
$this->Features(),
$featuresGridFieldConfig
);
$fields->addFieldToTab('Root.Features', $featuresGridField);