|
|||||||
![]() |
|
|
Thread Tools |
|
#1
|
|||
|
|||
|
Hi,
Is is possible to set up a sort key for a store based on the data. i.e. I am recieving: ['Bob','Tom','Fred','Jim'] but I want it to sort as Jim,Fred,Bob,Tom. So somehow I want to put a sortkey to those like: switch(name){
case 'Jim':
store.data.sortKey = 1;
break;
case 'Fred':
store.data.sortKey = 2;
break;
case 'Bob':
store.data.sortKey = 3;
break;
case 'Tom':
store.data.sortKey = 4;
break;
default:
store.data.sortKey = 5;
}
Thanks for your time and support,
__________________
------------ Brandon |
|
#2
|
|||
|
|||
|
yess, i dont see why not. I also dont see why you couldnt just apply the sorting on the server before you send it though...
|
|
#3
|
|||
|
|||
|
This data is being pulled from another source so I don't have control over the sorting that I recieve. With that, what do you think is the best method for doing this? I already have it set up to make the sortKey in a renderer and that seems to be working fine but then when I try to sort the grid using :
grid.store.sort('sortKey','ASC'); or grid.getStore().sort('sortKey','ASC')
Thank you for your help,
__________________
------------ Brandon |
|
#4
|
|||
|
|||
|
i think after you sort the store, the grid wont get an event telling it to update its view so you have to do it manually. (grid.getView().refresh() i think, check the api).
|
|
#5
|
|||
|
|||
|
I'm getting a "this.grid is null or not an object" error when I try to do grid.getView().refresh. That looked like it was the proper way to do it from the API, I'm not quite sure why I would be getting this error at this point.
Thanks for your help,
__________________
------------ Brandon |
|
#6
|
|||
|
|||
|
Ok, I need to rehash this one. I have it now built so that it creates a sortKey column and fills it based on the status column. The problem is that when I try to set that column as the default sort it will show it as selected but it wasn't sorted.
My renderer: function sortKey(val,p,record){
switch(val.toLowerCase()){
case 'new':
record.data.sortKey = 1;
break;
case 'broken':
record.data.sortKey = 2;
break;
case 'destroyed':
record.data.sortKey = 3;
break;
default:
record.data.sortKey = 4;
}
return val;
}
Anyone have any idea about this one or have a better idea of how to do this? Thanks for your help,
__________________
------------ Brandon |
|
#7
|
||||
|
||||
|
Why not define a custom sortType, e.g.
function sortStatus(value){
switch(value.toLowerCase()){
case 'new':
return 1;
case 'broken':
return 2;
case 'destroyed':
return 3;
}
return 4;
}
var store = new Ext.data.Store({
fields: [
{name: 'status', sortType: sortStatus},
...
],
...
});
store.sort('status', 'ASC');
|
|
#8
|
|||
|
|||
|
That would definately be the alternate solution I was looking for. Works like a charm. Thank you very much for showing me that one as that will come in real handy with a few of the grids I am building.
![]()
__________________
------------ Brandon |
|
#9
|
|||
|
|||
|
Real quick for someone who has access to the API, it probably needs to be updated. Under Ext.data.Record.create when it talks about sortType it does not mention that it can be a custom sortType nor does Ext.data.SortTypes. Actually Ext.data.Record.create says for sortType that it is "A member of Ext.data.SortTypes". Granted, I should have looked at the code to figure it out but it would be nice to see that in the API.
Just a suggestion Thanks,
__________________
------------ Brandon |
|
#10
|
||||
|
||||
|
I hope this isn't seen as thread hijacking, my question is closely related.
In the app that I'm building I am using a custom renderer in a grid to show a column of company IDs as company names. Unfortunately this means that the sort order in the grid is wrong. I was hoping that I'd be able to write a simple comparison function like those used by PHP's usort function. Is there something else that I'm missing? |
![]() |
| Thread Tools | |
|
|