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.

Table calls sortInternalRows with externalSorting=true

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, post on Stackoverflow or Gitter

Current behavior

When externalSorting is enabled, the sortInternalRows() method is still called due to this commit: https://github.com/swimlane/ngx-datatable/commit/67a4e8aeaf6c03e7fa3bc6a6d0a34725ec1c6b0a This causes the rows to change their sort order in undesirable ways after they are passed to the datatable component. Single sorting seems to work fine, but when combined with [sortType]="'multi'" the sort order is incorrect.

I believe the additional call to sortInternalRows() added to the translateColumns() method should be changed to:

if (!this.externalSorting) {
    this.sortInternalRows();
}

Expected behavior

Multi sorting would work correctly with externalSorting=true and the grid would never attempt to sort the rows itself.

Reproduction of the problem

Turn on [externalSorting]="true" and [sortType]="'multi'" and see that the sortInternalRows() method is called.

Please tell us about your environment:

  • Table version: 11.3.0
  • Angular version: 5.2.4
  • Browser: Chrome 67.0.3396.99
  • Language: TypeScript 2.5.3

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:1
  • Comments:5

github_iconTop GitHub Comments

1reaction
mc-sucheckicommented, Sep 7, 2018

As nobody from the ngx-datatable seems to answer this issue, I downgraded the package to 11.2.0. However, I quickly discovered that this creates another bug in my app. The fix for it was merged in 13.0.1: https://github.com/swimlane/ngx-datatable/pull/1375

Moreover, in our case the sorting issue exists even with [sortType] set to 'single'.

Therefore, I came up with the workaround - define a Noop comparator like so:

   <ngx-datatable-column
      ...
     [comparator]="noopComparator"
     ...
>
 public noopComparator(): number {
    return 0;
 }

This looks bad, but fixes the issue, allowing us to use the latest version. We can remove rxjs-compat now by the way. 👍

I hope this helps @dmartinzar @ronsc @lecongbang90!

0reactions
DzmVasileuskycommented, Jan 14, 2020

This issue also affects [sorts] input. For example if you are sorting a table from outside and then want to apply correct view state to column header. [externalSorting]="true" [sorts]="externalSort$ | async" will cause client side sorting.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Fastest table sort in the West - Redesigning DuckDB's sort
DuckDB recently improved its sorting implementation, which is now able to sort data in parallel and sort more data than fits in memory....
Read more >
External Sorting - GeeksforGeeks
The external merge sort algorithm, which sorts chunks that each fit in RAM, then merges the sorted chunks together.
Read more >
All you need to know about sorting in Postgres - Madusudanan
External merge is much like Merge sort. It is used when the data does not fit in memory. This is probably the slowest...
Read more >
Display tag external sort overriden? - Stack Overflow
On the controller side, i get the sorted column index and the sort order. String c = request.getAttribute(new ParamEncoder("tableId").
Read more >
TBSORT—sort a table - IBM
The sort information record is maintained with the table. This record contains the order of the "last-sort" and provides for rows to be...
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