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.

Sorting-Classes in Table-Header not applied correctly on initial load

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 creating a DataTable with default sorting some of the css classes inside <datatable-header-cell> are wrong. See Reproduction of the problem for more information.

Expected behavior

On initial load the css classes should be set correctly.

Reproduction of the problem

Create a DataTable with default sorting.

@Component({
  selector: 'app-root',
  template: `
    <ngx-datatable
      [rows]="rows"
      [columns]="columns"
      [sorts]="sorts">
    </ngx-datatable>
  `,
})
export class AppComponent {

  rows = [
    { name: 'Austin', gender: 'Male', company: 'Swimlane' },
    { name: 'Dany', gender: 'Male', company: 'KFC' },
    { name: 'Molly', gender: 'Female', company: 'Burger King' },
  ];

  columns = [
    { prop: 'name' },
    { name: 'Gender' },
    { name: 'Company' }
  ];

  sorts = [
    {
      prop: 'name',
      dir: 'desc'
    },
  ];
}

The table is sorted descending according to the column name. This is correct.

But there is a problem with the header: Inside the <datatable-header-cell> there is a <span> which is used by css themes to display icons indicating the sort direction. The span has the classes sort-btn sort-desc undefined. Instead of undefined it should have the value of sortAscending or sortDescending according to the documentation.

Bildschirmfoto 2020-02-28 um 10 34 42

If you click the header to sort the items manually the css classes are applied correctly.

This problem occurs in the official examples, too. See default sorting. The sorting is active for column name.

What is the motivation / use case for changing the behavior?

On initial load the sorting direction can’t be displayed correctly when using css to display sorting icons.

Please tell us about your environment: Angular 8/9, NPM, macOS

  • Table version: 16.0.3

  • Angular version: Angular 8/9

  • 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 ] all

  • Language: [all | TypeScript X.X | ES6/7 | ES5] all

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:5
  • Comments:5

github_iconTop GitHub Comments

1reaction
zankevichcommented, Apr 7, 2020

@amcdnl Can we merge this? Looks like a proper fix. https://github.com/swimlane/ngx-datatable/pull/1835

1reaction
sansantoshcommented, Mar 5, 2020
Read more comments on GitHub >

github_iconTop Results From Across the Web

Headers not lining up properly with sorting_desc_disabled or ...
When using Scollerm, the sorting_disabled class causes the column headers to be misaligned because the columns where it is applied are too short ......
Read more >
ng-class not correct on initial pageload - Stack Overflow
This issue has been frustrating me for a while. When loading the page, default sorting for a table is set via this code:...
Read more >
Table Options - Bootstrap Table
The table options API of Bootstrap Table. ... These buttons can be sorted with the table option buttonsOrder, the used key/name for the...
Read more >
jQuery tablesorter 2.0 - GitHub Pages
Property Type Default Link cancelSelection Boolean true cssAsc String "" cssChildRow String "tablesorter‑childRow" 1 2
Read more >
Angular Material Data Table: A Complete Example
Sortable Headers and Server-side Sorting; Server-side Filtering with Material Input Box; A Loading Indicator; A Custom Angular Material CDK Data ...
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