Looks like we can't reproduce the issue or there's a problem in the test case provided.
  1. #1
    Sencha User
    Join Date
    Jun 2008
    Posts
    157
    Vote Rating
    0
    wiznia is on a distinguished road

      0  

    Default Grid sorting by different dataIndex

    Grid sorting by different dataIndex


    I know this is not a bug, but a feature request, but since I don't have permissions to post there, I'll post it here...
    I always run into a problem with grids, ordering and sorting. The problem is very common, you are displaying in a grid a field from another object, so you show the name of the object, but filter by it's id. Your column config is something like:
    Code:
    {
      dataIndex: 'category_id',
      header: 'Category',
      renderer: function(value, meta, record, rowIndex, colIndex, store, view) {
        return record.get('category_name');
      },
      filter: {
        type: "list",
        store: "categorystore"
      }
    }
    The problem comes when you want to sort, now if you put sortable:true then you will be sorting by id not name (which is what a user expects). You could change the dataIndex to "category_name", but then the filter would be in the wrong field. So the thing is that you can't specify different fields for sorting and filtering in a column.
    This can be solved in two ways, adding some config to the filter to specify which column should filter or add a config to the sorting. It tried it both, but since the code for the filtersfeature is still in development (in ext 4.0.2RC it's different than in RC1) I figured it was simpler to do it for the sorting. Here's the override:
    Code:
        Ext.override(Ext.grid.column.Column, {
            getSortParam: function() {
                return this.sortIndex || this.dataIndex;
            }
        });
    As you can see you can specify an additional option for the column 'sortIndex' that specifies which field to use. It could be implemented by passing the field in the 'sort' config, but that may break some applications that for some reason are sending a string in the sortable config.
    Is there any possibility of adding this to ext core??

  2. #2
    Sencha Premium Member
    Join Date
    Apr 2010
    Location
    Wellington, New Zealand
    Posts
    123
    Vote Rating
    5
    zerkms is on a distinguished road

      0  

    Default


    Actually I came to exactly the same solution.

    It would be great to have a separate config for the sorting/filtering.

  3. #3
    Sencha Premium Member
    Join Date
    Apr 2010
    Location
    Wellington, New Zealand
    Posts
    123
    Vote Rating
    5
    zerkms is on a distinguished road

      0  

    Default


    Uhm, guys, why closing without any comments?!

  4. #4
    Sencha - Ext JS Dev Team evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    17,050
    Vote Rating
    657
    evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute

      0  

    Default


    You can specify custom sorting types for fields.
    Evan Trimboli
    Sencha Developer
    Twitter - @evantrimboli
    Don't be afraid of the source code!

  5. #5
    Sencha Premium Member
    Join Date
    Apr 2010
    Location
    Wellington, New Zealand
    Posts
    123
    Vote Rating
    5
    zerkms is on a distinguished road

      0  

    Default


    Quote Originally Posted by evant View Post
    You can specify custom sorting types for fields.
    How? `dataIndex` is sent on server with server-side based sorting. How can we change it?

Thread Participants: 2