+ state: DataTableState = {
+ checkedList: {},
+ };
+ checkBoxColumn: DataColumn<any, any> = {
+ name: 'checkBoxColumn',
+ selected: true,
+ configurable: false,
+ filters: createTree(),
+ render: (uuid) => <input type='checkbox' name={uuid} color='primary' checked={this.state[uuid] ?? false} onChange={() => this.handleCheck(uuid)}></input>,
+ };
+
+ initializeCheckedList = (items: any[]): void => {
+ const checkedList = this.state;
+ for (const uuid in checkedList) {
+ if (checkedList.hasOwnProperty(uuid)) {
+ delete checkedList[uuid];
+ }
+ }
+ items.forEach((uuid) => {
+ if (!checkedList.hasOwnProperty[uuid]) {
+ checkedList[uuid] = false;
+ }
+ });
+ };
+
+ componentDidUpdate(prevProps: Readonly<DataTableProps<T>>): void {
+ if (prevProps.items !== this.props.items) {
+ this.initializeCheckedList(this.props.items);
+ }
+ }
+
+ handleCheck = async (uuid: string) => {
+ const checkedList = this.state;
+ const newCheckedList = { ...checkedList };
+ newCheckedList[uuid] = !checkedList[uuid];
+ await this.setState(newCheckedList);
+ };