Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PF4 Table: 'Select All' checkbox updates #1368

Merged
merged 1 commit into from
Feb 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions packages/patternfly-4/react-table/src/components/Table/Table.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,18 @@ class Table extends React.Component {
this.state = {
headerData: []
};
this.isSelected = this.isSelected.bind(this);
this.areAllRowsSelected = this.areAllRowsSelected.bind(this);
}

isSelected(row) {
return row.selected === true;
}

areAllRowsSelected(rows) {
return rows.every(this.isSelected);
Copy link
Member

@dlabrecq dlabrecq Feb 11, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we skip expanded row children?

It's odd that both parent and child have a selected property because they could be initialized differently and/or be out of sync. In addition, setting the selected property on a child has no affect on its parent.

Copy link
Member Author

@dtaylor113 dtaylor113 Feb 11, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that fix maybe on your onSelected method, similar to the doc example here -you'll need to weed out the child rows w/o checkboxes in your method, and not set them to row.selected = true.

Copy link
Member

@dlabrecq dlabrecq Feb 11, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I weed them out myself, will rows.every(this.selected) still work?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's good idea to skip expanded children. There is option to show checkbox for expanded children as well, that might be handy in future once we figure out tree tables.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds reasonable. Thanks for the explanation

}

render() {
const {
caption,
Expand Down Expand Up @@ -169,6 +180,7 @@ class Table extends React.Component {
sortBy,
onSort,
onSelect,
allRowsSelected: onSelect ? this.areAllRowsSelected(rows) : false,
actions,
onCollapse,
rowLabeledBy,
Expand Down
Loading