亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在 SilverStripe 4 上編輯 many_many_extraFields?

如何在 SilverStripe 4 上編輯 many_many_extraFields?

PHP
慕婉清6462132 2021-08-28 16:18:49
我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()
查看完整描述

1 回答

?
慕田峪4524236

TA貢獻1875條經驗 獲得超5個贊

在 SilverStripe 3 和 4 中,我們可以使用 SilverStripe GridField 擴展模塊的GridFieldEditableColumns 功能來編輯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);


查看完整回答
反對 回復 2021-08-28
  • 1 回答
  • 0 關注
  • 129 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號