All checkboxes in a group were checked when i check one row in group
See original GitHub issueI’m submitting a …
[X ] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here, post on Stackoverflow or Gitter
Current behavior I have grouped data with checkboxes. When i check a checkbox in a row, all rows in the group get checked.
Expected behavior When i check one row in a group, only the checkbox of this row have to be checked
Reproduction of the problem Open https://stackblitz.com/edit/angular-ngx-table-chebox-bug. Expand a Group (female or male) and try to check a checkbox of a single row.
Our fix
In template:
<ngx-datatable ... [rowIdentity]="fixRowIdentity">
In component:
const fixedRowIdentity = (x: any) => x
What is the motivation / use case for changing the behavior? I want to select single rows with checkboxes from different groups
-
Table version: 16.0.3
-
Angular version: 8.2.14
-
Browser: Chrome Version 80.0.3987.116 (Official Build) (64-bit)
-
Language: TS 3.5.3
Issue Analytics
- State:
- Created 4 years ago
- Comments:12
Top GitHub Comments
IMO this is caused by #1778
https://github.com/swimlane/ngx-datatable/commit/3372d63d579f3c27f8da542ce0c7b7df4b2d15c9#diff-d15e451d9c07f1930dee554115082076R771-R778
This introduced
getRowExpandedIdx
which internally usesrowIdentity
. The defaultrowIdentity
has a context-based side-effect. It behaves differently if it’s context tells, that the table is grouped. IfrowIdentity
thinks the table is grouped, it treats the given row as a group object{key: ..., value: []}
. ThegetRowExpandedIdx
functionality usesrowIdentity
on row objects, even if the table is grouped, sorowIdentity
tries to treat a row like a group object.I fixed with this rowIdentity function: fixedRowIdentity(x: any) { if(x.key) return x.key; return x.id }
this check if have “key” attribute for groups and “id” for rows