Skip to content

Commit

Permalink
Fix: Improve tree all selection
Browse files Browse the repository at this point in the history
  • Loading branch information
Domino987 committed Jan 10, 2023
1 parent 12a65dd commit ba0fda9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/components/MTableHeader/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ export function MTableHeader({
props.selectedCount > 0 && props.selectedCount < props.dataCount
}
checked={
props.dataCount > 0 && props.selectedCount === props.dataCount
props.dataCount > 0 && props.selectedCount >= props.dataCount
}
onChange={(event, checked) =>
props.onAllSelected && props.onAllSelected(checked)
Expand Down
3 changes: 2 additions & 1 deletion src/material-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -1017,7 +1017,7 @@ export default class MaterialTable extends React.Component {
selectedCount={this.state.selectedCount}
dataCount={
props.parentChildData
? this.state.originalData.length
? this.state.treefiedDataLength
: this.state.columns.some((col) => col.tableData.groupOrder > -1)
? this.state.groupedDataLength
: this.state.data.length
Expand Down Expand Up @@ -1184,6 +1184,7 @@ export default class MaterialTable extends React.Component {
<Droppable droppableId="headers" direction="horizontal">
{(provided, snapshot) => {
const table = this.renderTable(props);
console.log('state', this.state);
return (
<div ref={provided.innerRef}>
<div
Expand Down
8 changes: 8 additions & 0 deletions src/utils/data-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,16 @@ export default class DataManager {

setCheck(this.groupedData);
} else {
const checkChild = (row) => {
row.tableData.childRows &&
row.tableData.childRows.forEach((child) => {
child.tableData.checked = isChecked(row);
checkChild(child);
});
};
this.searchedData.forEach((row) => {
row.tableData.checked = isChecked(row);
checkChild(row);
});
selectedCount = this.searchedData.length;
}
Expand Down

0 comments on commit ba0fda9

Please sign in to comment.