PDA

View Full Version : How to use a different field for sorting in EditorGridPanel?



wgpubs
18 Oct 2010, 10:12 PM
One of the fields in my EditorGridPanel references the Id of a child object related to each record in the grid. In fact, I return both the "Id" AND the "Name" of the child object (Id for use by a combo for editing and Name for display purposes) for each record.

What I want to know is if I can tell the GridPanel to sort by child "Name" rather than child "Id" when the column bound to the child "Id" field is clicked?

Thanks



{ name: 'Child.Id', mapping: 'childId', },
{ name: 'Child.Name', mapping:'childName' },




{ header: "ChildName", width: 40, sortable: true, dataIndex: 'Child.Id',editor: comboEditorForChild, renderer: rendererForChild },

Condor
18 Oct 2010, 11:12 PM
1. It's a really bad idea to use '.' in a field name.
2. You can change the sorting behavior by specifying a sortType function in the field definition. Unfortunately, sortType doesn't get passed the full record, so you need this patch (http://www.sencha.com/forum/showthread.php?71668-Customizable-sorting-of-stores-grids&p=345372#post345372).

wgpubs
18 Oct 2010, 11:26 PM
re: 1 ... I use the "." operator as it enables me to automatically update the child objects on the server. I'm using ASP.NET MVC but the same goes with using Rails. I know it presents a problem for certain things and have had to resort to array accessors to get at individual records in my Ext code.

re: 2 ... I'm not sure if the patch really fits (or at least I'm not sure how). I really just want to say, "When clicking on the column associated to 'Child.Id' set sort='Child.Abbr'"

Thanks -wg

Condor
19 Oct 2010, 1:25 AM
Use the mentioned patch and return the Child.Abbr value from the Child.Id sortType function.