4

After the grid has been loaded with the data, if we try to sort any column, the default direction is ascending. Can we define a default sort for grid column such that after I load the grid, if I click on that column, it should get sorted in descending order first. I dont want to sort the grid with that column in that direction when it is loaded. This should happen after the grid has been loaded with the values. I am using remote Sort. So, I am clearing all the sorters whenever the grid is loaded so that it does not remember the previous sorting.I tried adding sorter dynamically on the server side but that would result in grid getting sorted with that property and direction when it is loaded which I dont want. I tried using sortInfo, it wont work.

Need it immediately, will be really thankful if anyone could answer this. Thank you so much.

user2316489
  • 159
  • 1
  • 4
  • 14

1 Answers1

7

Try to add sorters to your store:

Ext.define('SuggestedOrders.store.SODetails',
{
    extend: 'Ext.data.Store',
    // some more of your code
    sorters:
    {
        field: 'column you need to sort by',
        direction: 'DESC'
    }
});

ADDENDUM:

You need to remove remoteSort: true option. When this is set you will not be able to click on your column/attribute header to change it's sorting direction. Try without it and let me know ;)

Brian
  • 4,623
  • 8
  • 35
  • 54
  • Hey I tried that but its not working because on the server side, the sorters are being removed while creating the window. I tried adding dynamically but that results in grid already being sorted in that direction when loaded which I dont want. Do you know of any other method using which I can seta default sort for a particular column. SO, I want when the grid is loaded, and when I click on any column, some columns to be sorted in ascending order and some to be in descending order. – user2316489 Mar 27 '14 at 16:54
  • Edited, take a look. You should not use `remoteSort: true` in the case when you want to manually click on column headers and change their sorting directions\ – Brian Mar 27 '14 at 17:32
  • No I cannot do that as it is getting sorted on the server side. Do you know of any way using which once the grid is loaded it should have descending order as its default sort direction. – user2316489 Mar 28 '14 at 14:18
  • What is the point, I do not get your comment. Just make your `PHP` return you in `DESC` oreder. Why would you sort on server side and again resort in DESC onrder once the store is loaded? – Brian Mar 28 '14 at 15:23
  • No, I do not want the grid to be sorted in descending order when it is loaded, I want it to be loaded that is, the page is refreshed, the grid is now opened with new values, now at any point of time if I click on this column for the first time, it should sort in descending order as opposed to ascending which is default. SO i tried using sortDir in model for this column, I tried using sorters in store, nothing would work. – user2316489 Mar 28 '14 at 16:11
  • ANd also, The grid is loaded without any sort being made. For ex, I have A,B, C,D columns in my grid and my grid is now loaded. Now after playing with it for sometime, if I click on column A for the first time, it should sort in descending order and when I click on any other column, ie. B,C or D for the first time, it should sort in ascending order first. – user2316489 Mar 28 '14 at 16:13
  • The problem is that YOU CANNOT CLICK on column to sort when you have 'remoteSort: true'. Just to understand what I mean, comment out that line, refresh the browser and click on columns. They should change their sort dir – Brian Mar 28 '14 at 16:16