【发布时间】:2020-09-23 06:45:52
【问题描述】:
由于无限行模型不支持参数headerCheckboxSelection=true,
我需要创建自己的复选框。
所以问题是,如何在第一列标题中添加一个具有必要 api 功能的复选框?
使用自定义标题会重置所有标题的所有过滤、排序、样式和菜单选项,是否可以只为第一个标题执行此操作?
我试过设置第一列def columnDef.headerComponentFramework = CustomCheckbox,或者
columnDef.headerComponent = CustomCheckbox,或将它们用作字符串,但我得到的只是这个错误:
Warning: React.createElement: type is invalid -- expected a string (for built-in components or a class/function (for composite components) but got: undefined.
这是我的复选框组件:
export default class customCheckbox extends Component {
constructor(props) {
super(props);
console.log(props)
this.state = {
checked: false,
};
}
updateState = e => {
this.setState({ checked: e.value });
if (!this.state.checked) this.selectAllRows(true);
if (this.state.checked) this.selectAllRows(false);
};
selectAllRows = bool => {
this.props.api.forEachNode(row => {
this.props.api.getRowNode(row.id).selectThisNode(bool);
});
};
render() {
return (
<div className="custom-header-checkbox">
<CheckBox value={this.state.checked} onChange={this.updateState} />
</div>
);
}
}
编辑:
我得到了复选框来显示将复选框组件更改为函数并使用此headerComponentFramework = CustomCheckboxFunction,但我无法将 api 传递给它
【问题讨论】: