Datatable doesn't sort data correctly
See original GitHub issueI’m submitting a … (check one with “x”)
[x] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here
Current behavior Sorting is not preserved on data update. Example: Current data: [ { id: 1, val: 10}, {id:2, val: 5} ] Clicking on “val” column will sort data this way: [ {id:2, val: 5}, { id: 1, val: 10} ] A new item is added (entire array is replaced as “immutable”): [ {id:2, val: 5}, { id: 1, val: 10}, { id:3, val: 1 } ] Sorting is inconsistent.
Expected behavior Example: Current data: [ { id: 1, val: 10}, {id:2, val: 5} ] Clicking on “val” column will sort data this way: [ {id:2, val: 5}, { id: 1, val: 10} ] A new item is added (entire array is replaced as “immutable”): [ {id:2, val: 5}, { id: 1, val: 10}, { id:3, val: 1 } ] Datatable detects update and sorts data again: [ { id:3, val: 1 }, {id:2, val: 5}, { id: 1, val: 10} ] A workaround should at least remove sort indicator from the column headers as data is sorted no more.
Reproduction of the problem Sort data and fetch it again from server.
What is the motivation / use case for changing the behavior? If it is Datatable to handle sorting it should also be in charge of keeping it consistent with the view on updates.
Please tell us about your environment: OSX, jspm/Systemjs, nginx
-
Table version: 1.4.1
-
Angular version: 2.2.0
-
Browser: all
-
Language: TypeScript 2.1.1
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:7 (4 by maintainers)
Top GitHub Comments
Fixed.
@pantonis setting
rows
andsorts
property must be passed a new object before updates are applied after version 10. Modifying the existing object (i.e.this.rows.push(...data);
) will no longer work.Try doing something like this
this.rows = [...this.rows];
after any collection mutation.