Skip to content

Commit ba0fda9

Browse files
author
Domino987
committed
Fix: Improve tree all selection
1 parent 12a65dd commit ba0fda9

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

src/components/MTableHeader/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ export function MTableHeader({
355355
props.selectedCount > 0 && props.selectedCount < props.dataCount
356356
}
357357
checked={
358-
props.dataCount > 0 && props.selectedCount === props.dataCount
358+
props.dataCount > 0 && props.selectedCount >= props.dataCount
359359
}
360360
onChange={(event, checked) =>
361361
props.onAllSelected && props.onAllSelected(checked)

src/material-table.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1017,7 +1017,7 @@ export default class MaterialTable extends React.Component {
10171017
selectedCount={this.state.selectedCount}
10181018
dataCount={
10191019
props.parentChildData
1020-
? this.state.originalData.length
1020+
? this.state.treefiedDataLength
10211021
: this.state.columns.some((col) => col.tableData.groupOrder > -1)
10221022
? this.state.groupedDataLength
10231023
: this.state.data.length
@@ -1184,6 +1184,7 @@ export default class MaterialTable extends React.Component {
11841184
<Droppable droppableId="headers" direction="horizontal">
11851185
{(provided, snapshot) => {
11861186
const table = this.renderTable(props);
1187+
console.log('state', this.state);
11871188
return (
11881189
<div ref={provided.innerRef}>
11891190
<div

src/utils/data-manager.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,8 +378,16 @@ export default class DataManager {
378378

379379
setCheck(this.groupedData);
380380
} else {
381+
const checkChild = (row) => {
382+
row.tableData.childRows &&
383+
row.tableData.childRows.forEach((child) => {
384+
child.tableData.checked = isChecked(row);
385+
checkChild(child);
386+
});
387+
};
381388
this.searchedData.forEach((row) => {
382389
row.tableData.checked = isChecked(row);
390+
checkChild(row);
383391
});
384392
selectedCount = this.searchedData.length;
385393
}

0 commit comments

Comments
 (0)