【问题标题】:How do I add checkboxes to admin-on-rest datagrid component?如何将复选框添加到 admin-on-rest 数据网格组件?
【发布时间】:2017-07-24 20:37:44
【问题描述】:

Datagrid 组件包装了 material-ui 的 Table 组件,根据 admin-on-rest 文档,您可以通过 headerOptions、rowOptions、bodyOptions 和 options 属性传递 material-ui 表选项(例如显示复选框的选项) .根据 material-ui 文档,选项是 showCheckboxes 和可选择的。我还发现在网上提到了其他一些内容,例如 displayRowCheckboxes。

正如您在下面的代码中看到的,我已经疯狂地尝试了所有方法。没有任何效果。

<List {...props} sort={{ field: "id", order: "ASC" }}>
<Datagrid 
  headerOptions={{displaySelectAll: true}} 
  rowOptions={{selectable: true}}
  bodyOptions={{showCheckboxes: true, displayRowCheckBox: true}} 
  options={{showCheckboxes: true, onRowSelection: ()=>{}}}>
  <TextField label="FIRST NAME" source="first_name" />
  <TextField label="LAST NANE" source="last_name" />
  <EditButton />
</Datagrid>
</List>;

这给了我一个不可选中的标题复选框,但没有行复选框:

【问题讨论】:

    标签: material-ui admin-on-rest


    【解决方案1】:

    回答我自己的问题:

    <Datagrid 
      headerOptions={{ adjustForCheckbox: true, displaySelectAll: true }} 
      bodyOptions={{ displayRowCheckbox: true }} 
      rowOptions={{ selectable: true }} 
      options={{ multiSelectable: true }}>
      <TextField label="FIRST NAME" source="first_name" />
      <TextField label="LAST BANE" source="last_name" />
      <EditButton />
    </Datagrid>
    

    ;

    【讨论】:

      猜你喜欢
      • 2011-07-03
      • 2014-03-01
      • 2019-11-02
      • 1970-01-01
      • 2013-04-25
      • 2011-09-23
      • 2012-08-25
      • 2015-08-10
      • 1970-01-01
      相关资源
      最近更新 更多