有没有一种方法可以对MUI-dataTable中的列进行分组?

时间:2020-09-29 10:27:55

标签: reactjs mui-datatable

我在我的React项目中使用MUIDataTable。我只想通过在表中添加边框来对列进行分组。请在下面找到我正在使用的代码。

const columns = [
 {
  name: "name",
  label: "Name",
  options: {
   filter: true,
   sort: true,
   [customBodyRender: (value) => {
          return (
            <div style={{ borderRight: "solid 2px" }} >
              {value}
            </div>
          )
        }][1]
  }
 },
 {
  name: "company",
  label: "Company",
  options: {
   filter: true,
   sort: false,
  }
 },
 {
  name: "city",
  label: "City",
  options: {
   filter: true,
   sort: false,
   customBodyRender: (value) => {
          return (
            <div style={{ borderRight: "solid 2px" }} >
              {value}
            </div>
          )
        }
  }
 },
 {
  name: "state",
  label: "State",
  options: {
   filter: true,
   sort: false,
  }
 },
];

const data = [
 { name: "Joe James", company: "Test Corp", city: "Yonkers", state: "NY" },
 { name: "John Walsh", company: "Test Corp", city: "Hartford", state: "CT" },
 { name: "Bob Herm", company: "Test Corp", city: "Tampa", state: "FL" },
 { name: "James Houston", company: "Test Corp", city: "Dallas", state: "TX" },
 { name: "", company: "", city: "Tampa", state: "" },
    { name: "", company: "", city: "", state: "" },
    { name: "", company: "", city: "Hartford", state: "" },
    { name: "", company: "", city: "", state: "" },
    { name: "", company: "", city: "", state: "" },
    { name: "", company: "", city: "", state: "" },
];
 
const options = {
  filterType: 'checkbox',
};
 
<MUIDataTable
  title={"Employee List"}
  data={data}
  columns={columns}
  options={options}
/>

这无法正常工作。边框高度不合适或在表行中没有数据的情况下,根本没有边框。 我也希望边框出现在表格标题上。

我已附上输出快照以供参考。 OutputImage

有没有办法解决这个问题?

1 个答案:

答案 0 :(得分:0)

有一个 PR 但它只是测试版 https://github.com/gregnb/mui-datatables/pull/1441,尚未合并到主分支