我正在使用 jQuery tablesorter 插件对 asp.net 应用程序中的 gridview 进行排序。我可以捕获列索引,但似乎无法弄清楚如何获取列名。
这就是我正在做的事情:
var currentSort;
$('#gvTickets').tablesorter({
// sort on the last column, order asc
sortList: [[9, 0]]
}).bind("sortEnd", function(sorter) {
currentSort = sorter.target.config.sortList;
});
这是html:
<div>
<table class="stretchalltable" cellspacing="0" rules="all" border="1" id="gvTickets" style="border-collapse:collapse;">
<thead>
<tr>
<th scope="col" class="header" style="cursor: pointer; ">Requester</th><th scope="col" class="header" style="cursor: pointer; ">Subject</th><th scope="col" class="header" style="cursor: pointer; ">Type</th><th scope="col" class="header" style="cursor: pointer; ">Category</th><th scope="col" class="header" style="cursor: pointer; ">Priority</th><th scope="col" class="header" style="cursor: pointer; ">Status</th><th scope="col" class="header" style="cursor: pointer; ">Due</th><th scope="col" class="header" style="cursor: pointer; ">Assigned To</th><th scope="col" class="header" style="cursor: pointer; ">Created</th><th scope="col" class="header headerSortUp" style="cursor: pointer; ">Days</th>
</tr>
</thead><tbody>
<tr>
<td>JMAULDIN</td><td><a href="ticket2.aspx?action=edit&ticket_id=7827">Van Order Entry Customer Contract Lookup Display</a></td><td>Project</td><td>Portal </td><td>Normal</td><td>On Hold</td><td> </td><td>Nathan Baker - Doozer</td><td>27-DEC-2011</td><td>133</td>
</tr><tr style="background-color:#E6E6E6;">
<td>RCRITTENDEN</td><td><a href="ticket2.aspx?action=edit&ticket_id=8190">Cap changes</a></td><td>Project</td><td>Portal </td><td>Normal</td><td>On Hold</td><td> </td><td>Nathan Baker - Doozer</td><td>02-FEB-2012</td><td>106</td>
</tr><tr style="background-color:#E6E6E6;">
<td>JMAULDIN</td><td><a href="ticket2.aspx?action=edit&ticket_id=8796">Online SRN -- Add email SRN like print SRN</a></td><td>Project</td><td>Portal </td><td>Normal</td><td>New</td><td> </td><td>Nathan Baker - Doozer</td><td>15-MAR-2012</td><td>76</td>
</tr><tr>
<td>JMAULDIN</td><td><a href="ticket2.aspx?action=edit&ticket_id=9058">SES AST field not saving correctly.</a></td><td>Project</td><td>Portal </td><td>Normal</td><td>On Hold</td><td> </td><td>Nathan Baker - Doozer</td><td>20-MAR-2012</td><td>73</td>
</tr><tr>
<td>RAVRIETT</td><td><a href="ticket2.aspx?action=edit&ticket_id=9470">Copy Project Plan (ignore deleted items)</a></td><td>Support Task</td><td>Loaned Item </td><td>Normal</td><td>New</td><td> </td><td>Nathan Baker - Doozer</td><td>24-APR-2012</td><td>48</td>
</tr><tr>
<td>TCACCAM</td><td><a href="ticket2.aspx?action=edit&ticket_id=9670">WEB: Contracts Administration</a></td><td>Support Task</td><td>Portal </td><td>High</td><td>New</td><td>14-MAY-2012</td><td>Nathan Baker - Doozer</td><td>14-MAY-2012</td><td>34</td>
</tr><tr style="background-color:#E6E6E6;">
<td>DOOZER1</td><td><a href="ticket2.aspx?action=edit&ticket_id=10041">nb test</a></td><td>Project</td><td>Portal </td><td>Normal</td><td>New</td><td>13-JUN-2012</td><td>Nathan Baker - Doozer</td><td>13-JUN-2012</td><td>12</td>
</tr></tbody>
</table>
</div>
更新
感谢您对 fudgey 的回复。无论我尝试什么,我似乎都无法让它工作。基本上我需要做的是在 jquery 表排序器中,我需要让 sortList 值成为一个变量。它需要看起来像这样:
var currentSort;
$('#gvTickets').tablesorter({
// sort on the last column, order asc
sortList: currentSort
}).bind("sortEnd", function(sorter) {
currentSort = sorter.target.config.sortList;
});
我需要将 currentSort 存储在 Session 中并通过 ajax 调用检索它,然后以与上次查看时相同的方式对网格进行排序。如果用户点击页面,对网格进行排序,离开页面然后返回,只要它在会话状态的范围内,我需要以与他们上次在页面上相同的方式对其进行排序。