ui-grid icon indicating copy to clipboard operation
ui-grid copied to clipboard

Default Column Sort Direction

Open strider820 opened this issue 13 years ago • 13 comments

Is there any way to give a column a default sort direction? The problem I'm having is that I have a few number columns, and they default to sort low-to-high when they're sorted initially, but I need them to default to high-to-low first.

I've been looking through the api and code, and I'm not seeing anything. Am I missing something, or is this not currently possible?

strider820 avatar Jul 15 '13 19:07 strider820

You can use sortInfo: {fields:['field'], directions:['asc']} or sortInfo: {fields:['field'], directions:['desc']}

pro85 avatar Jul 16 '13 07:07 pro85

That defaults the column to being sorted when the grid is initialized. That's not what I'm looking for. What I want is when a user clicks to sort a specific column, I want it to default to desc rather than asc.

strider820 avatar Jul 16 '13 15:07 strider820

Hi, I'm also running into this issue.

http://stackoverflow.com/questions/17657134/how-do-you-update-ng-grid-gridoptions-sortinfo

You can set the column to sort on using an undocumented method

$scope.gridOptions.sortBy('name');

But you can't currently update the sortInfo object or sort direction. Would be very useful if this was added.

In addition, my unit Karma/Jasmine unit tests complain when I use the sortBy() method as they don;t seem to recognise it.

EdL avatar Jul 23 '13 13:07 EdL

Is this issue is fixed? If Yes So what and where to add additional info in grid configuration. Thanks in Advance.

vikasrana1989 avatar Aug 13 '14 10:08 vikasrana1989

This issue is more of a feature request, and no it has not been added. If someone submits a PR I will happily merge it.

c0bra avatar Aug 18 '14 18:08 c0bra

Thank You!

vikasrana1989 avatar Aug 19 '14 05:08 vikasrana1989

Hi @c0bra, I have submitted a PR with the fix. If you could merge it, I'll be very thankful.

Thanks!

ghost avatar Oct 19 '14 05:10 ghost

@elirankon: Was the PR by you, ever merged in? I am also looking for a way to set the 'first' sort order (on column header click) to descending instead of ascending.... Thank you.

kmittal avatar Apr 27 '15 16:04 kmittal

Hi Kushagra,

Yes, it was merged into the 2.x branch.

On Mon, Apr 27, 2015 at 7:54 PM, Kushagra Mittal [email protected] wrote:

@elirankon https://github.com/elirankon: Was the PR by you, ever merged in? I am also looking for a way to set the 'first' sort order (on column header click) to descending instead of ascending.... Thank you.

— Reply to this email directly or view it on GitHub https://github.com/angular-ui/ng-grid/issues/561#issuecomment-96738651.


Eliran Kononowicz +972-545-442913

ghost avatar Apr 27 '15 16:04 ghost

@elirankon : Thanks for responding. Can you please tell me what's the solution or where can I look for the fix... Its hard for me to track it down in the pull requests log.

kmittal avatar Apr 28 '15 15:04 kmittal

@kmittal PR link: https://github.com/angular-ui/ng-grid/pull/1864

SteGriff avatar May 21 '15 09:05 SteGriff

Update: use the sort property of a columnDef to specify a default sort direction at init.

Doc: http://ui-grid.info/docs/#/api/ui.grid.class:GridOptions.columnDef

{ field: 'DateCreation', sort: { direction: uiGridConstants.DESC }, }

fretman92 avatar Jan 04 '16 14:01 fretman92

If you are sorting after init (meaning not sorting on init, but after data has been loaded, etc) and have externalSorting: true, how would you manually tell ui-grid to set a particular column to sorted?

Ui-grid has 3 clicks to do asc, desc, and clearing sort respectively. I want to recreate like a "default" scenario. Currently, my data is being returned as sorted by spendAmount asc whenever a sorting param is not defined in the api request, therefore, I would like to tell ui-grid to put the desc indicator on the spendAmount column manually.

edlahoz avatar Sep 26 '16 19:09 edlahoz