Ngx-datatable: sortable: false is being ignored

Created on 2 May 2017  路  8Comments  路  Source: swimlane/ngx-datatable








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

sortable: false in column definitions is being ignored.

Expected behavior

Columns defined with sortable: false should not be sortable.

Reproduction of the problem

With remote sorting enabled, if you define your columns and assign them sortable: false they are still sortable.

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

So you can make your columns unsortable.

Please tell us about your environment:

  • Table version: 9.0.0

  • Angular version: 4.0.0

  • Browser: [all]

  • Language: [all]

Investigate

Most helpful comment

@lobo-tuerto, curious, are you using ngx-datatable-column in your template? And if so, are you explicitly passing in [sortable]="columnObj.sortable" or something like that?

I got burned on that because I thought that if you pass columns into the ngx-datatable itself with a particular column having sortable be false, it would pick it up. However, apparently, if you specify a custom ngx-datatable-column, you have to pass that input into that explicitly. Once you do, it does what you would expect.

Perhaps, @amcdnl can correct me on that if I am wrong.

All 8 comments

comparator as well

@lobo-tuerto, curious, are you using ngx-datatable-column in your template? And if so, are you explicitly passing in [sortable]="columnObj.sortable" or something like that?

I got burned on that because I thought that if you pass columns into the ngx-datatable itself with a particular column having sortable be false, it would pick it up. However, apparently, if you specify a custom ngx-datatable-column, you have to pass that input into that explicitly. Once you do, it does what you would expect.

Perhaps, @amcdnl can correct me on that if I am wrong.

@ychaikin Yeah, exactly that was my asumption too!!

Thanks a lot for taking your time to explain the solution, I think this should be in the documentation somewhere, maybe in the column definition section.

@amcdnl Would it be bad design or difficult (or possible at all) to pick the sortable config from the columns definition if not passed explicitly to ngx-datatable-column?

If you are using ngx-datatable, and you are are using ngx-datatable-column, for each column, to disable the "sort" you have to add "[sortable]="false"" for each ngx-datatable-column, example:

<ngx-datatable ...>
<ngx-datatable-column name="First Name" [sortable]="false" prop="firstName" />
</ngx-datatable>

Doing this, you are disabling the "sort" capability in the column header for each column.

Can someone please help with this one?

<ngx-datatable-column [minWidth]="100" [maxWidth]="100" [sortable]='false'>
won't work.

the following works for me:

<ngx-datatable-column [sortable]="false" prop="id" name="ID"></ngx-datatable-column>

using:

[externalPaging]="true"
[externalSorting]="true"

using version 11.2.0 with Angular 5

[sortable]='false' does not work, Angular 6.1.0

Was this page helpful?
0 / 5 - 0 ratings