1. #1
    Sencha User
    Join Date
    Apr 2014
    Posts
    46
    Vote Rating
    1
    varmaj80 is on a distinguished road

      0  

    Default Unanswered: How to set a particular column in the grid as the default sort column?.

    Unanswered: How to set a particular column in the grid as the default sort column?.


    Hello All,
    I am doing a search and get all the search results to a grid. Whenever I do a search, I want one particular column to be my default sort column with the values getting sorted in ascending order. Once I get the search results, I may select a different column header and do a sort on that particular column. And when I reset the page or do the search once again, I want the default column header to be highlighted and the values sorted based on that column values. Right now , if I click on a column header and do a search again, the same column header is getting highlighted in the new search results.

    For example, say have 3 columns in my grid. FirstName, LastName and Entered Date. I want the Entered Date column to be my default sort column header everytime the page loads or the grid loads or after every search. Eventhough I select the FirstName header and do a sort on that column manually, if I do a search again, I want the Entered Date column header to be highlighted and sorted.
    Can anyone give me an idea of how this can be done?.

  2. #2
    Sencha User
    Join Date
    Sep 2013
    Posts
    29
    Vote Rating
    1
    Answers
    1
    mwilliamsShields is on a distinguished road

      0  

    Default


    I believe you can sort the column by using <TheColumnYouWouldLikeToSort>.setSortState("ASC");

    setSortState is what is called when a column is clicked, so it should work well.

    Here are the docs:
    http://docs.sencha.com/extjs/4.2.2/#...d-setSortState
    Last edited by mwilliamsShields; 19 Sep 2014 at 6:04 AM. Reason: Quick reply messed with the formatting

  3. #3
    Sencha User
    Join Date
    Apr 2014
    Posts
    46
    Vote Rating
    1
    varmaj80 is on a distinguished road

      0  

    Default


    I tried this but this is not working for me. Nothing is happening when I use the enteredDate.setSortState("ASC"); in my view page. I really doubt if the column headers change their state for every search. I guess whenever I am doing a search in a particular page, the column headers wont refresh and only the results section gets refreshed. So is there any way to see the column headers also gets refreshed after every search.

  4. #4
    Sencha User
    Join Date
    Sep 2013
    Posts
    29
    Vote Rating
    1
    Answers
    1
    mwilliamsShields is on a distinguished road

      0  

    Default


    Are you calling the setSortState as the page loads? If you are that could have to do with why that isn't working. If you call it whenever a search is done then it should work.

    To have it sort when the page loads you should give the store that is associated to your grid a sorter. You should set the direction config to 'ASC' and the property config to the name of the column as it is named in the model.

  5. #5
    Sencha User
    Join Date
    Apr 2014
    Posts
    46
    Vote Rating
    1
    varmaj80 is on a distinguished road

      0  

    Default


    Hello Williams,

    I tried giving a sorter to the store and it worked fine when the page loads first time. Its working as I want it to be. But the problem arises only when I try to click on a different column header in the grid. When I click on a different header it sorts based on that particular column values. If I click on search button at this point of time without reloading the page, the search results get displayed and are sorted based on my previous selected column. I want this to be sorted based on the default column. Problem is the grid gets refreshed with search results every time I click on search or reset buttons but the column headers are not getting refreshed. So the results are getting sorted based on my previous selection. To fix this problem, I am trying to reload the whole page every time I click on search or reset. Is there a way that I can refresh the column headers along with the search results every time I click on the search so that the results get sorted based on the default column header. I am able to refresh the search results and the pagination part for every search but not the column headers. Any solution...

    Thanks....

  6. #6
    Sencha User
    Join Date
    Sep 2013
    Posts
    29
    Vote Rating
    1
    Answers
    1
    mwilliamsShields is on a distinguished road

      0  

    Default


    I would try calling the setSortState function every time you click on the search. I suspect that the reason that didn't work for you earlier is because you were doing it when the page loaded. However if you call enteredDate.setSortState("ASC"); when search is clicked then it should work fine.

Thread Participants: 1

Tags for this Thread