question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Datatable doesn't sort data correctly

See original GitHub issue

I’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:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
amcdnlcommented, Nov 17, 2016

Fixed.

0reactions
wizarrccommented, Sep 11, 2017

@pantonis setting rows and sorts 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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Sort Not Working Correctly — DataTables forums
Hi! I'm trying to sort a table on a column that contains a variety of data, specifically a number (which will have either...
Read more >
jquery datatables column not sorting properly - Stack Overflow
What I have is a table with a few columns all of which work as far as sorting goes except one. below is...
Read more >
Datatable sort not working with custom data types
I tried creating a lightning-datatable with custom data types, but unfortunately when trying to sort a column, it does not work.
Read more >
DataTable Sorting - Documentation - Webix
DataTable allows you to sort data rows on the client side. ... For this purpose, DataTable provides several sorting types to ensure correct...
Read more >
DataTables Sorting & Searching not working - Laracasts
I am using data tables in Laravel. ... When I click ordering, it does not sort. Searching returns no match even though I...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found