Hybrid View

  1. #1
    Sencha User
    Join Date
    Oct 2012
    Posts
    3
    Vote Rating
    0
    dk75 is on a distinguished road

      0  

    Default Unanswered: Grid default sort and filter issue

    Unanswered: Grid default sort and filter issue


    Hi

    We are using server-side sorting and filtering for GXT grid.

    For first-time load, there is a default sort and filter implemented on server: if no filter/sort provided in request, default ones are used. The problem is, that column headers looks like there is no filter/sort until user set it manually from client-side. We want grid to display column headers in different style from the very first load, as if default filter and sort were set manually by user: arrows, italic font, filter value(s) in submenu.

    I noticed that PagingLoadResultBean that server returns to client contains only start and count values for pagination toolbar (in additon to dataset records), but not filterConfig or sortInfo. Thus server is unable to inform client about default filter/sort, and these should be set on client somehow before the request. So I were searching for methods to set default values when GridFilters is created during grid setup. But didn't find anything.

    I believe this is quite a standard problem and solution must exist. Could anyone please advise ?
    Thanks.

  2. #2
    Ext GWT Premium Member icfantv's Avatar
    Join Date
    Sep 2011
    Location
    Superior, CO
    Posts
    411
    Answers
    20
    Vote Rating
    21
    icfantv will become famous soon enough icfantv will become famous soon enough

      0  

    Default


    I know I've seen something before, perhaps even here in the forums, about the sorting arrow problem. It has been asked before.

    Regarding filters. There is no built-in mechanism for the server to tell the client the default sort order and active filters because those are meant to be client-side driven.

    Have you looked at the filter grid example here: http://www.sencha.com/examples/#ExamplePlace:filtergrid?

    You'll note that the filters are extraneous to the grid and you can set the state (enabled or disabled) of them. Note that depending on when this is done, your grid may or may not request the data.

    If you want to set the values of the filters programmatically, this behavior is not directly supported and you will have to extend the filter classes to expose this ability. Our filters are not part of the grid column header and so this is the course we've had to go so that we can still use GXT's grid filtering API.

  3. #3
    Sencha User
    Join Date
    Oct 2012
    Posts
    3
    Vote Rating
    0
    dk75 is on a distinguished road

      0  

    Default


    Thank you for quick answer.

    Quote Originally Posted by icfantv View Post
    Have you looked at the filter grid example
    ...
    Yes, we have seen all samples and have no problems implementing filters in general.
    The problem is that when user sees grid first time it must be already sorted and filtered by default. And grid UI must inform user about that, just as if user has performed this sort/filter manually.
    This is very common use case.

    Quote Originally Posted by icfantv View Post
    If you want to set the values of the filters programmatically...
    Yes.

  4. #4
    Ext GWT Premium Member icfantv's Avatar
    Join Date
    Sep 2011
    Location
    Superior, CO
    Posts
    411
    Answers
    20
    Vote Rating
    21
    icfantv will become famous soon enough icfantv will become famous soon enough

      0  

    Default


    Right, I understand. I'm not sure how to set the arrow to indicate the initial sorting, but for the filters, if you have your initial grid load done via something like:

    Code:
    Grid<M> g = new Grid<M>(ListStore, ColumnModel)
    {
       @Override
       protected void onAfterFirstAttach() // you could also try onAfterRenderView()
       {
          // call your loader.load() method here
       }
    };
    This may give you enough time to set your filter values. Again, the built-in GXT filters don't allow direct editing, that is, you can only set these filter values by interacting with the UI via the column header menu - you'll need to extend and use your own implementation of these filters to do this.

  5. #5
    Sencha - GXT Dev Team
    Join Date
    Jan 2012
    Location
    Arlington, WA
    Posts
    453
    Answers
    7
    Vote Rating
    15
    branflake2267 will become famous soon enough

      0  

    Default


    This can set the sort direction. Call this after the initial load.

    Code:
    int colIndex = 0;
    grid.getView().getHeader().updateSortIcon(colIndex, SortDir.ASC);

  6. #6
    Sencha User
    Join Date
    Oct 2012
    Posts
    3
    Vote Rating
    0
    dk75 is on a distinguished road

      0  

    Default


    Quote Originally Posted by branflake2267 View Post
    This can set the sort direction. Call this after the initial load.

    Code:
    int colIndex = 0;
    grid.getView().getHeader().updateSortIcon(colIndex, SortDir.ASC);
    Thank you. Such code adds ASC marker, but when user clicks on column first time marker and actual sort order remains "ASC" , although the expected result would be switching to "DESC". This works more correctly:
    Code:
    loader.addSortInfo((new SortInfoBean(column.getPath(), SortDir.ASC)));
    Sort is ok. For filter, however, a question remains open.