PDA

View Full Version : Grid Server & Client Side Sorting



AtulDawkhare
31 Oct 2011, 11:27 PM
Hi ,
I have a Grid Component working very fine. I have used Proxy 'ajax'. And I am able to sort the columns also.

My Question is, Can we have a option to sort the column at server side [Java code] OR sort at Client side [i.e. Sorting in the data that is there in Gird but no call to server java code]

So something like switch button, where If I say sort Server side then go call to server's java code and if I say sort Client side then Sort within the data that is currently displayed.

Here is my store:



var store = Ext.create('Ext.data.Store', {
pageSize: 10,
model: 'ForumThread',
remoteSort: true,
proxy: {
autoSave: true,
autoSync:true,
type: 'ajax',
api: {
create : '/GridDemo?create=true',
read : '/GridDemo?read=true',
update : '/GridDemo?update=true',
destroy : '/GridDemo?destroy=true'
},

reader: {
root: 'topics',
totalProperty: 'totalCount'
},
writer: {
type : 'json',
writeAllFields : true,
allowSingle : true,
encode : true,
root : 'row'
},

simpleSortMode: true
},
sorters: [{
property: 'Updated_date',
direction: 'DESC'
}]
});

flanders
1 Nov 2011, 12:48 AM
If I read your question correctly you want to choose between server and client side sorting?

You do this using the "remoteSort" option you are already using in your store configuration. Also, a quick look at the code doesn't show any reason why you cannot change this property after instantiation.

AtulDawkhare
1 Nov 2011, 1:14 AM
Thanks a lot for this Quick Reply.

yes , I knew that this can be handle by using remoteSort , My queries is, I want to have something like button on the Grid who will decide which sorting I am looking for.

Means at run time user and not the developer will decide he want server side sorting or Client side sorting.

Hope I am able to explain well this time.

flanders
1 Nov 2011, 2:09 AM
I figured that you wanted to change it after instantiation. Thats why I said I don't see any reason you cannot change it after creating the grid.

But if you're asking for an approach on this; there are several. I personally would add a toolbar to the grid with two radio input fields and listen to the change event of these. (Of course you can use buttons as well.) In your event handler you can than set remoteSort to true or false on the grid instance. This should do the trick.

AtulDawkhare
1 Nov 2011, 2:59 AM
Thanks a lot.
I have implemented using the Button and it is working very fine.

Thanks a lot for the Quick help.

Jimmey2013
10 May 2013, 10:17 AM
Do you guys have any solution on how to make the sorting work on all pages (not just current page) ?
I am looking for client side sorting solution.
Please share your your ideas on how to achieve client side sorting in grid.
Thanks in adavance.:)

Jimmey2013
10 May 2013, 10:20 AM
Hi AtulDawkhar (http://www.sencha.com/forum/member.php?306903-AtulDawkhare),
Could you share your solution to achive the sorting on client side ?