I saw lots of topic regarding RadGrid client sort topic and I couldn't get the answer after I searched lots.most of them using PageMethods.function -- still call function on server side. Is it any way not to go to server side and sort on clientside only?
I tried to use the following sample but I can't figure out where I can get data from. I don't use the webservice so can't use PageMethods.functionName(). Also I don't want to go to server at all. Is it possible?
12 Answers, 1 is accepted
the Telerik team
the Telerik team
here is my grid
when i am using your code i am getting error :
data is not define...
send me an example.
I guess you want to bind RadGrid from serverside and sort from client side.If this is the desired functionality, unfortunately it is not supported. The sorting functionality is performed over the data source to which the RadGrid is bound. If you bound the RadGrid on the server a post back is needed in order to apply sorting expression and return sorted data. If you want to have client side sorting you need to bind the RadGrid on the client.
- Hook up radGrid_Command(sender, args) to the client side command event by using the ClientEvents-OnCommand attribute on the ClientSettings element of the grid.
- Set the SortExpression attribute to the UniqueName of the column for GridTemplateColumns.
This allows the code to find the correct column index.
- Set AllowNaturalSort attribute on MasterTableView element to false which will stop all postbacks related to sorting.
If AllowNaturalSort = true, a postback will occur for the natural sort but the client code will be called for asc and desc sorts.
This was written for our specific purpose and environment and may require some changes to work properly in your environment. This should provide a good launching point for a pure client side sort. From what we have seen so far, this has not affected anything on the server side and the grid works as it should after a client side sort.
Thank you for share your example for simple client sorting. I'm sure it will be of a big help to other users that need to implement similar scenarios.
However, the args.set_cancel(true) does not seem to be canceling the postback. I've also tried aborting the postback through the page request manager to no avail. So, when the postback occurs the columns come back unsorted.
Any thoughts on canceling the postback?
I have tried the above code and it works fine.One suggestion to prevent postback on clicking the header is you can use RadAjaxPanel or RadAjaxManager.
Please try and see if it helps.
I believe that you may have the AllowNaturalSort property set to true (the default value). When this is set to true, it will post back the third time you click a column to rebind the grid in it's natural sort order. This can be set on the MasterTableView element or GridTableView object.