swimlane / ngx-datatable

✨ A feature-rich yet lightweight data-table crafted for Angular
http://swimlane.github.io/ngx-datatable/
MIT License
4.63k stars 1.68k forks source link

Checkbox selected rows update #961

Open FrancescoBorzi opened 7 years ago

FrancescoBorzi commented 7 years ago

I'm submitting a ... (check one with "x")

[ ] bug report => search github for a similar issue or PR before submitting
[x] feature request
[ ] support request => Please do not submit support request here, post on Stackoverflow or Gitter

Current behavior [selected]="selectedRows" does not update the selectedRows array when new rows are selected

Expected behavior it would be nice if it does

wizarrc commented 7 years ago

@ShinDarth the table is using OnPush change detection now. Have you tried passing a copy of the selectedRows every time it changes? An easy way of doing that is to use the spread operator upon making the change. Example:

<ngx-datatable
   ...
   [selectedRows]="selectedRows">
<ngx-datatable>
...
...
export class demo {
    selectedRows: any[];
...
...
    addRowToSelection(row: any) {
        ...
        this.selectedRows.push(row); // Example of how you might make a change that won't be detected with OnPush
        ...
        this.selectedRows = [...this.selectedRows]; // However you updated the rows, use this to make a copy
    }
}
FrancescoBorzi commented 7 years ago

yes I saw that, I'm just saying that it would be better if there was a way to do it automatically

wizarrc commented 7 years ago

@ShinDarth Doing change detection on an unbounded very large array can be quite expensive. If you were to want something automatic, and performant, then you would have to shift the burden to the collection to notify the table. I am working on a fork of the project that allows an observable collection to be passed to the table, and it will subscribe to any changes, then all changes would be made to that special collection object from your perspective.

I don't see a future for allowing a regular array to make any change and have it automatically detected in the table.

ashokseshan commented 6 years ago

Hi, I do have an issue with selected checkbox count update. The count is getting updated after some action like scroll up and scroll down. Is there any fix for this please ??