ngx-datatable icon indicating copy to clipboard operation
ngx-datatable copied to clipboard

Sorting DESC on first column click instead of ASC

Open maustand opened this issue 7 years ago • 14 comments

I'm submitting a ... (check one with "x")

[ ] bug report => search github for a similar issue or PR before submitting
[x] feature request
[ ] support request => Please do not submit support request here, post on Stackoverflow or Gitter

Current behavior The current sorting behavior is working ASC on the first click and there is not any property to specify the the default sorting direction on the first click.

Expected behavior It would be great to have a property, lets say 'sortingDirectionAtFirst', where we could change the sorting direcction on the first click. currently the datatable is working very well, but there is not any way to change the direccion on the first click to DESC for all the columns.

        <ngx-datatable
            class="material"
            [rows]="reportData"
            [sortingDirectionAtFirst]="DESC">    
</ngx-datatable>     

What is the motivation / use case for changing the behavior? It would be nice to have the ability to change the sorting direction at the first click.

Please tell us about your environment:

  • Table version: 10.2.3
  • Angular version: 4.0.0
  • Browser: All
  • Language: TypeScript 2.4.2

Thank you

maustand avatar Oct 01 '17 16:10 maustand

@maustand what about the direction of subsequent sorts sorting direction at first click? Example of that would be to sort by last name, then by first, then by middle. But someone might want the sort direction different for each header cell clicked, or depending on the specific context. It might be easier to get a callback when header cell is clicked and you can decide for yourself the direction.

wizarrc avatar Oct 01 '17 17:10 wizarrc

Chiming that I would find this feature very useful

Ryan-Haines avatar Nov 29 '17 15:11 Ryan-Haines

Totally behind this idea - in almost every case, for our use cases, the first click would want to be descending, as opposed to ascending. Having this controllable as an option per column would be awesome.

mrjamesriley avatar Feb 23 '18 12:02 mrjamesriley

I would also find this very useful. It would be nice to have the option to choose the order of the initial sort order.

lajon9 avatar May 12 '18 18:05 lajon9

+1

rev-valery avatar Jul 01 '19 11:07 rev-valery

Use this [sorts]="[{prop: 'name', dir: 'asc'}]" it will set sort direction to ascending order. when you click on column for the first time it will sort in desc direction

RaghuRaghavendra664 avatar Jul 31 '19 05:07 RaghuRaghavendra664

Use this [sorts]="[{prop: 'name', dir: 'asc'}]" it will set sort direction to ascending order. when you click on column for the first time it will sort in desc direction

It will make this column sorted by default when the table is rendered

ali9itani avatar Oct 15 '19 12:10 ali9itani

I would find this very useful too.

mpintener avatar Jun 02 '20 15:06 mpintener

Is there any known workaround for this one?

stankovicmilutin avatar Apr 07 '21 12:04 stankovicmilutin

Would second this request but would need it to be on a column by column basis. Example use case, We have a table of items with string and number columns. We want to configure the string columns to sort ascending by default and the numbers to sort descending by default.

pmacn avatar Feb 01 '22 15:02 pmacn

I support this issue too

DanNisenson avatar Sep 14 '23 12:09 DanNisenson

@DanNisenson I have made a workaround for this tho. First I converted numbers to negative ones and had css class to change icon in the header, and then converted value in the cell again to positive number.

stankovicmilutin avatar Sep 14 '23 12:09 stankovicmilutin

what do you mean by:

First I converted numbers to negative ones

DanNisenson avatar Sep 14 '23 12:09 DanNisenson

Well column was with numbers, so by X * -1, it goes in other direction

stankovicmilutin avatar Sep 14 '23 12:09 stankovicmilutin

I see. I have multiple data types in my row cells so I'm gonna need to find another solution, but thanks for the tip!

DanNisenson avatar Sep 14 '23 12:09 DanNisenson