这就是我渲染表格主体的方式:
<tbody {...getTableBodyProps()}>
{rows.map((row, i) => {
prepareRow(row);
return (
<Row {...row.getRowProps()}>
{row.cells.map((cell) => {
// return <td {...cell.getCellProps()}>{cell.render("Cell")}</td>;
return cell.render("Cell");
})}
</Row>
);
})}
</tbody>
Run Code Online (Sandbox Code Playgroud)
这就是我设置列的方式。我为每个单元格创建了独特的组件。
[
{
Header: "Main Header",
Footer: "Foot",
columns: [
{
Header: "Code",
accessor: "NominalCode",
Cell: (props) => {
return <CodeCell>{props.cell.value}</CodeCell>;
},
Footer: () => {
return <FooterTotalCell>Total</FooterTotalCell>;
}
},
{
Header: "Description",
accessor: "Description",
Cell: (props) => {
return (
<DescriptionCell country={props.row.values.Currency}>
{String(props.cell.value)}
</DescriptionCell>
);
},
Footer: () => {
return <td />; …Run Code Online (Sandbox Code Playgroud) react-table ×1