我已经建立了一个有 180 行的表。该表位于此网址:
http://mywebbapp.com/tableSortingDemo.html
我想显示表格中的总行数。但是jquery tablesorter插件我只显示基于选择框值的行数。该插件没有为应该隐藏的行提供显示的 css 属性,它只是完全删除了这些行。所以我的显示计数器显示以下内容:
“查看 1 -5 of 5” 我希望它显示“查看 1-5 of 180”。然后,当我单击分页链接时,它们不会增加到“查看 180 个中的 6-10 个”等等,只是保持不变。下面是我的代码。
$(document).ready(function ()
{
// add new widget called repeatHeaders
$.tablesorter.addWidget({
// give the widget a id
id: "repeatHeaders",
// format is called when the on init and when a sorting has finished
format: function (table) {
// cache and collect all TH headers
if (!this.headers) {
var h = this.headers = [];
$("thead th", table).each(function () {
h.push("" + $(this).text() + "");
});
}
// remove appended headers by classname.
$("tr.repated-header", table).remove();
// loop all tr elements and insert a copy of the "headers"
for (var i = 0; i < table.tBodies[0].rows.length; i++) {
// insert a copy of the table head every 10th row
if ((i % 5) == 4) {
$("tbody tr:eq(" + i + ")", table).before($("").html(this.headers.join("")));
}
}
}
});
$("table")
.tablesorter({ widthFixed: true, widgets: ['zebra'], headers: {
5: {
sorter: false
},
6: {
sorter: false
},
7: {
sorter: false
},
8: {
sorter: false
}
}
})
.tablesorterPager({ container: $("#pager") });
$('#pager').css({ 'top': '', 'position': 'relative', 'text-align': 'center' });
$('#pager img').click(function () {
$('#pager').css({ 'top': '', 'position': 'relative', 'text-align': 'center' });
getCurrentRows($('.pagesize').val(), pageDisplay, $('#ClaimsList tbody tr').length);
});
$('.pagesize').click(function () {
$('#pager').css({ 'top': '', 'position': 'relative', 'text-align': 'center' });
});
var pageSize = $(".pagesize").val();
var pageDisplay = parseInt($('.pagedisplay').val());
function getCurrentRows(rowsPerPage, currPage, rowCount) {
var from = (rowsPerPage * currPage) - rowsPerPage + 1;
var to = (rowsPerPage * currPage) > rowCount ? rowCount : rowsPerPage * currPage;
return $('#viewRowCount').html("Viewing " + from + " -" + to + " of " + rowCount);
}
getCurrentRows($('.pagesize').val(), pageDisplay, $('#ClaimsList tbody tr').length);
$('.pagesize').change(function () {
getCurrentRows($('.pagesize').val(), pageDisplay, $('#ClaimsList tbody tr').length);
});
});
解决这个问题的好方法是什么?