I'm submitting a ... (check one with "x")
bug report
Current behavior
Add doesn't work if sorting is enabled
Expected behavior
Add works fine even if sorting is enabled
Reproduction of the problem
Basic/Live Data page demo in a browserAdd button at the topWhat is the motivation / use case for changing the behavior?
Adding rows while sorting is set? :)
Please tell us about your environment:
Windows 8.1 x64
Node 7.7.3
Table version: 0.8.x
The latest from the repo
Angular version: 2.0.x
The latest from the repo
Browser: [all | Chrome XX | Firefox XX | IE XX | Safari XX | Mobile Chrome XX | Android X.X Web Browser | iOS XX Safari | iOS XX UIWebView | iOS XX WKWebView ]
Chrome 58.0.3029.81
Language: [all | TypeScript X.X | ES6/7 | ES5]
all
This is the case also with remove.
Same for me (8.2.1) :(
Edit : No difference with 9.0.0.
Windows 8.1 x64
@angular/cli 1.0.1
Node 6.9.1
Chrome 57.0.2987.133
I have disallowed sorting until this is fixed - a blocker otherwise, cannot afford to have live data not shown.
Can one of you guys make a demo in plunkr showing this? It would be very helpful in debugging.
Hi,
As the OP has mentioned in his report, you can see this in the live demo.
http://swimlane.github.io/ngx-datatable/
(and click Live Data under Basic).
From that demo, and more precisely:
I suspect the sorting action has resulted with the array reference of table data changing, and add/remove is acting on an old reference, hence no change visible?...
I have seen this bug for client-side sorting only (9.2.0)
If I set [externalSorting]="true", it works fine.
sortRows() returns the copy of rows.
https://github.com/swimlane/ngx-datatable/blob/9.2.0/src/utils/sort.ts#L67
If we enable client-side sorting, this copy will be assigned to ngx-datatable's rows.
https://github.com/swimlane/ngx-datatable/blob/9.2.0/src/components/datatable.component.ts#L107
So, our rows array has different reference from ngx-datatable's rows at the beginning.
My work around is re-assigning rows after modified.
this.rows.push({});
this.rows = [...this.rows];
This was my terrible workaround.
onSort(event) {
let sortProp = event.column.prop;
let localRows = _.cloneDeep(this.rows);
localRows = _.orderBy(localRows, [row => parseInt(row[sortProp]) ? row[sortProp] : row[sortProp].toLowerCase()], [event.newValue]);
this.rows = [];
this.rows = _.cloneDeep(localRows);
}
@amcdnl So you've got the demo. Looking forward to a resolution.
Most helpful comment
sortRows() returns the copy of rows.
https://github.com/swimlane/ngx-datatable/blob/9.2.0/src/utils/sort.ts#L67
If we enable client-side sorting, this copy will be assigned to ngx-datatable's rows.
https://github.com/swimlane/ngx-datatable/blob/9.2.0/src/components/datatable.component.ts#L107
So, our rows array has different reference from ngx-datatable's rows at the beginning.
My work around is re-assigning rows after modified.