reactjs - React Material - MUIDataTable - 有没有办法在标题中计算行数?
问题描述
有谁知道在标题中包含行数的方法?我似乎无法使用options或columns属性来做到这一点。
我想要实现的是:
第 1 列标题(行数)| 第 2 列标题 | ...... | N 列标题
提前感谢您的任何建议。
更多信息:
解决方案
请检查这个例子:
import React from "react";
import MUIDataTable from "mui-datatables";
export default class MuiDatatableHeader extends React.Component {
constructor(props) {
super(props);
this.state = {
filteredRowCount: 0
}
}
render() {
const columns = [
{
label: "Name",
name: "Name",
options: {
customHeadRender: (columnMeta, updateDirection) => (
`${columnMeta.name} (Total Count ${data.length})`
)
}
},
{
label: "Title", name: "Title",
options: {
customHeadRender: (columnMeta, updateDirection) => (
`${columnMeta.name} (Total Filter Row Count ${this.state.filteredRowCount})`
)
}
},
{name: "Location"},
{name: "Age"},
{name: "Salary"}
];
const data = [
["Gabby George", "Business Analyst", "Minneapolis", 30, "$100,000"],
["Aiden Lloyd", "Business Consultant", "Dallas", 55, "$200,000"]
];
const options = {
selectableRows: "multiple",
selectableRowsHeader: data.length > 0,
};
return (
<div>
<button onClick={() => {
this.setState({filteredRowCount: 10})
}}>Filter data
</button>
<MUIDataTable
title={"ACME Employee list"}
data={data}
columns={columns}
options={options}
/>
</div>
);
}
}
推荐阅读
- kotlin - 哪个 RxJava 运算符使它更简单
- dto - 为什么 DTO 不会在 nestjs 中引发验证错误?
- java - Spring-boot HttpMediaTypeNotAcceptableException 没有被同一控制器中的@ExceptionHandler 捕获
- amazon-ec2 - 如何在云形成模板中为根卷设置 aws ec2 的卷大小
- swift - 点击标记时打印特定键的用户数据
- python - 尝试在 Python 中的文件上写入格式化文本时出现问题
- javascript - 使用 JavaScript 获取日期,然后将其放入 PHP 数据库 - 将实际脚本放入不变量
- python - InvalidArgumentError:找到 2 个根错误。(0) 无效参数:不兼容的形状:[4,3] vs. [4,4]
- ios - 如何在应用商店应用信息部分更改应用内购买列表的顺序?
- bash - 从命名管道读取错误