Default Column Sort Direction
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?
You can use
sortInfo: {fields:['field'], directions:['asc']}
or
sortInfo: {fields:['field'], directions:['desc']}
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.
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.
Is this issue is fixed? If Yes So what and where to add additional info in grid configuration. Thanks in Advance.
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.
Thank You!
Hi @c0bra, I have submitted a PR with the fix. If you could merge it, I'll be very thankful.
Thanks!
@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.
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
@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 PR link: https://github.com/angular-ui/ng-grid/pull/1864
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 }, }
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.