我正在使用jQuery.tablesorter.js来允许我在单击表头时对表列进行排序。
但是,我需要能够在排序后将表添加到表的最后一行(底部)。我有下面的代码,但这会将类添加到第一行(顶行),而不是最后一行。
我能做些什么来确保我总能得到最后一排吗?
<html>
<head>
<script language="JavaScript" src="../Generic/JAVASCRIPT/jquery.js" type="text/javascript"></script>
<script language="JavaScript" src="../Generic/javascript/jquery.tablesorter.js" type="text/javascript"></script>
<style>
table{ border: 3px solid #000000;}
th{ border-width: 2px; border-color: #000000; border-style: solid; background-color: #CFCFCF; color: #000000; }
td{ border-width: 2px; border-color: #000000; border-style: solid; }
td.lastRow{ background:red; }
</style>
<script>
$(document).ready(function()
{
$("#STable").tablesorter();
$('.header').click(function()
{
$('.lastRow').removeClass("lastRow");
$('.field1:last').addClass("lastRow");
$('.field3:last').addClass("lastRow");
}
)
}
);
</script>
</head>
<body>
<table id="STable">
<thead>
<tr>
<th class="header ">FIELDx1</th>
<th class="header headerSortDown">FIELDx2</th>
<th class="header headerTopRight">FIELDx3</th>
</tr>
</thead>
<tbody>
<tr class="TableRow">
<td class="field1" data-value="1">aaa</td>
<td class="field2" data-value="1">111</td>
<td class="field3" data-value="1">aaa111</td>
</tr>
<tr class="TableRow">
<td class="field1" data-value="2">bbb</td>
<td class="field2" data-value="2">222</td>
<td class="field3" data-value="2">bbb222</td>
</tr>
<tr class="TableRow">
<td class="field1 lastRow" data-value="3">ccc</td>
<td class="field2" data-value="3">333</td>
<td class="field3 lastRow" data-value="3">ccc333</td>
</tr>
</tbody>
</table>
</body>
</html>
答案 0 :(得分:0)
找到答案:
$("#STable").bind("sortStart",function()
{
$(".TableRow td.field1:last").removeClass("lastRow");
$(".TableRow td.field3:last").removeClass("lastRow");
}
).bind("sortEnd",function()
{
$(".TableRow td.field1:last").addClass("lastRow");
$(".TableRow td.field3:last").addClass("lastRow");
}
);