首页 > 解决方案 > 将 mui-datatables 数据的全选复选框添加为对象(自定义列)

问题描述

当我的数据是对象格式(自定义列)而不是像带有大量样本的字符串的数组时,我无法在 mui-datatables 中添加一个复选框以选择全部。按照此处的文档,我尝试了使用customHeadRender功能,但没有被调用,我尝试使用customToolbar,它将加载全选复选框,但是当您选择行时触发,我需要在页面加载时使用该复选框。

谢谢

这是codesanbox

在此处输入图像描述

标签: javascriptreactjsmui-datatable

解决方案


只需selectableRowsHeader: true,在你的options道具中使用,你会没事的。

 ...
   const options = {
      filterType: "textField",
      fixedHeader: true,
      sort: true,
      search: true,
      selectableRows: "multiple",
      responsive: "scrollMaxHeight",
      rowsPerPage: 15,
      rowHove: true,
      selectableRowsHeader: true, //<---------- this should be true (not false)
 ...

工作演示在这里


推荐阅读