PDA

View Full Version : Send sort column number in paged grid in Ext 1.0



JeffHowden
1 Mar 2007, 12:47 AM
So, I know many of you extended the behavior of the 0.33 grid to send the name of the column that was sorted to the server. However, for those of you who need to use the Ext 1.0 version in the same way, here's how to do it (assuming ds is a variable that refers to your datastore and cm is a variable that refers to your column model):


ds.on('beforeload', function() {
ds.baseParams = {
sort: cm.getIndexById(ds.sortInfo.field)
};
});

Now, on the server, you'll see a form variable named "sort" that'll contain the index of the column that was sorted.

In my system, I actually take a look at the sort index to determine if it's supposed to be ASC (1) or DESC (-1). So, my sort value is determined like this:


ds.on('beforeload', function() {
ds.baseParams = {
sort: cm.getIndexById(ds.sortInfo.field) * ((ds.sortInfo.direction.toUpperCase() == 'DESC') ? -1 : 1)
};
});

So, if the 3rd column is sorted descending, I get -2 (remember, JS arrays start at 0) in the request to the server.

mikegiddens
1 Mar 2007, 10:47 PM
I have been looking to overload my grid requests with an extraVar and did this instead.


ds.baseParams = {extraVar:'value'};
ds.load({params:{start:0, limit:25}});


Do you see any reason why this is bad. If it is put into the params call it only gets sent the first time and then if using the paging it does not get passed after the inital load. Having it put directly into teh baseParams before load keeps it in the obj.

Any thoughts on why this may be bad or should I keep to the beforeload.

JeffHowden
1 Mar 2007, 11:35 PM
If you wish for the name/value pair specified in baseParams to always be sent that way (ie, the value portion never changes), then the baseParams is indeed the place to put it. If, however, you need for that value to be dynamic, then beforeload is how you go about updating it prior to the load() method being called.

gcpeters
2 Jun 2008, 11:16 AM
Hey, this was great for me. I was filtering with a form that was separate of my grid. My PagingToolbar was losing the filters when using any of the buttons. I used this code to simple augment the ds.baseParams object to reflect to state of the form before load. Just figured I would say thanks and post my issue in case anyone else is having my problem. Thanks.