1

I have tabular data that I would like to be sorted by clicking on column headers. I understand I can do this by passing the column to sort on to the server in the query string, and then returning the data back to the client to be displayed in the table. However, I would like to be able to switch between ascending and descending sorts if the user clicks on the same field twice.

I have considered using ASP.NET's session to remember the last field that was sorted on, but I am wondering if there is a more REST-ful approach?

I am using JQuery on the client and ASP.NET on the server.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
nfw
  • 3,853
  • 2
  • 19
  • 16
  • 1
    Why not use some plugins to do this.. say like tablesorter or jQGrid ? – Alok Swain Oct 31 '11 at 22:50
  • Normally you would use Page's [ViewState](http://stackoverflow.com/questions/250037/gridview-sorting-sortdirection-always-ascending/415759#415759) to store such attributes. – Tim Schmelter Oct 31 '11 at 23:06
  • Here is a good link showing how to do this and more: [http://mattberseth.com/blog/2007/10/a_yui_datatable_styled_gridvie.html](http://mattberseth.com/blog/2007/10/a_yui_datatable_styled_gridvie.html) – drdwilcox Oct 31 '11 at 23:02

2 Answers2

0

If you are passing column name in query string and reloading the page, you can also pass order=asc/order=desc as query parameter and store current order on as custom data attribute on column heading.

Zygimantas
  • 8,547
  • 7
  • 42
  • 54
0

I ended up using the JQuery tablesorter plugin to solve my issue.

nfw
  • 3,853
  • 2
  • 19
  • 16