1

I have a datagrid that is displaying data that is being returned from a stored procedure. That works fine. The problem is that I want to do sorting. I know that there is sorting functionality in the grid, however, I don't want to go back to the server and get a new set of data. What I want to do is just re-sort the data that is already being displayed.

Anyone have any ideas on how that is done?

Thanks!

UPDATE

Basically, I couldn't not find an easy solution to this issue. I tried updating my dataGrid to a gridView control and even that (for my particular issue) was difficult. I wound up un-doing all the changes and just adding another grid that had just the data I wanted for the requirement.

If anyone else has an issue like this I would recommend taking it out of a datagrid and writing it in jQuery. I could of written a table that had the data I wanted (and fully sortable using a plug-in mentioned below) in 15 minutes compared to the hours I spent trying to jam a square peg into a round hole.

2 Answers 2

1

One thing you can do is save the current result set into the users session, provided it isn't that large. You can then use the build in sorting capabilities of the DataGrid without dealing with a round trip to the database.

You will make a trip back to the server, but often the trip to the web server and back is far faster than the trip that involves the database.

Sign up to request clarification or add additional context in comments.

Comments

1

It sounds like what you're wanting is to do the sorting on the client-side (the built-in grid sorting is server-side, and it sounds like you don't want the round trip). If you're using jQuery, there are some very easy plugins to handle sorting a on the client. For example, with the tablesorter plugin (http://tablesorter.com/docs/), you can do this with one line of code:

jQuery(".gv").tablesorter();

Where gv is a css class used for all my tables (GridView controls in an ASP.net application).

You'll need to make sure that your DataGrid is rending a <thead> and <tbody>, see related question for a Javascript way to add these, or you can do it from the codebehind in the PreRender event: ASP.NET 2.0 - DataGrid with tbody / thead

4 Comments

Can you use this tablesorter plugin with datagrids? Or just gridviews? My current project (legacy) is using datagrids (originally written in 1.1). Is there a way to utilize this plugin with those?
Yes you can use with DataGrid. All the plugin cares about is whether there is an html <table> on the page.
I couldn't get this to work for my DG. It is probably more project related than the plugin. If I had my druthers and the time I would re-write the page using jQuery instead of DataGrids.
@Jeff V, updated answer with one more thing that you'll need to do.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.