【问题标题】:Sorting ModelAdmin Columns in related Silverstripe tables对相关 Silverstripe 表中的 ModelAdmin 列进行排序
【发布时间】:2016-05-19 12:15:25
【问题描述】:

默认情况下,在 Silverstripe 的 modeladmin 中,只有当前表的列是可排序的。在modeladmin中如何使相关表的列也可排序>?

【问题讨论】:

  • 可排序是什么意思?您是指 ModelAdmin 顶部 (3.3) 还是左侧 (3.1) 的搜索字段?还是您的意思是网格字段上的搜索图标?还是您使用 SortableGridfield 模块?
  • @Eagle Silverstripe 3.3.2 中 modeladmin 顶部的表/类名右侧的向上和向下箭头。

标签: php content-management-system silverstripe


【解决方案1】:

gridfield 列右侧的排序箭头来自GridFieldSortableHeader 组件。更多信息请查看documentation

将此代码放入您的“托管模型”中

public function getCMSFields()
{
    $fields = parent::getCMSFields();

    $grid = $fields->dataFieldByName('YourRelation');
    $gridConfig = $grid->getConfig();
    $gridConfig->addComponent(new GridFieldSortableHeader());

    return $fields;
}

【讨论】:

  • $grid = $fields->dataFieldByName('YourRelation'); 'YourRelation' 在 $many_many 数组中吗?
  • 是的。所以如果你有一个$many_many = ['Products' => 'Product']; 那么YourRelation 就是Products
猜你喜欢
  • 2023-03-11
  • 1970-01-01
  • 2016-02-04
  • 2013-11-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多