自定义GroupRow渲染(mbrn / MaterialTable)React

问题描述 投票:0回答:1

我正在自定义mbrn / material-table的groupRow,但是我没有找到执行此操作的任何文档。

https://material-table.com/#/docs/features/grouping

enter image description here

到目前为止,我设法使groupRow及其工作正常。但是现在我不知道如何在扩展groupRow时呈现表行。

我尝试使用MTableBody,但未显示记录

enter image description here

 <tr className="MuiTableRow-root">
    <td
      className="MuiTableCell-root MuiTableCell-alignLeft MuiTableCell-paddingNone MuiTableCell-body py-2"
      colSpan={visiblecolumns + isGroupedAndHidden}
    >
      <button className="d-flex Card w-100">
        <div className="ml-3 text-left">
          <div className="text--bold text--muted text--xs">
            {props.groups[0].title}
          </div>
          <div className="pt-1 pb-1">
            {groupheader.title == 'Priority' ? (
              <Priority value={groupData.value} />
            ) : groupheader.title == 'Time' ? (
              <DateFormatter value={groupData.value} relative={true} />
            ) : (
              groupData.value
            )}
          </div>
        </div>
        <div className="ListGroupHeader__meta d-flex align-items-center justify-content-end">
          <span className="ListGroupHeader__count ml-3 mr-1">
            {alerts.length}
          </span>{' '}
          alert{alerts.length > 1 ? 's' : ''}
          <ChevronRight
            className="text-muted"
            style={{ fontSize: '30px' }}
          />
        </div>
      </button>
      <MTableBody {...props} />
    </td>
  </tr>

这是我的代码的样子。太困惑了,我不知道要使它正常工作还缺少什么]

CodeSandBox:https://codesandbox.io/s/festive-bell-5d76e

reactjs react-table material-table react-material
1个回答
0
投票

由您提供参考,文件上写明

您可以使用覆盖components.GroupRow覆盖已分组的行组件>

这就是您所做的,您高估了整个组件,但是该组件具有很多您缺少的功能,例如扩展和显示组的内容。

这是原始组件-https://github.com/mbrn/material-table/blob/master/src/components/m-table-group-row.js

因此,您要做的就是复制和更改或创建具有相同功能的自己的组件。

在下一个示例中,我采用了原始组件,并根据您的结构进行了更改(这并不完美,只是向您展示了方法)。我复制了MTableGroupRow和MTableCell(因为Cell组件是TableRow的一部分,必须更改),然后将它们称为CustomGroupRow和CustomCell。

https://codesandbox.io/s/frosty-forest-su2dl

© www.soinside.com 2019 - 2024. All rights reserved.