Below is my pagination code, I tried to add a pager to it myself, but it always shows 1 record when there are zero and it doesnt count them up properly either and it doesnt update when the results shrink (via my searching code which just calls the paginate function (I tried atleast haha)
also i wondered instead of the pager inserting before or after, can i make it insert inside a placeholder div?
function paginate(table) {
$(table).each(function () {
var currentPage = 0;
var numPerPage = 30;
var pageCount = 0;
var pageNo = 0;
var $table = $(this);
$table.bind('repaginate', function () {
$table.children('tbody').children('tr:not(.exclude)').hide().slice(currentPage * numPerPage, (currentPage + 1) * numPerPage).show();
});
$table.trigger('repaginate');
var numRows = $table.children('tbody').children('tr:not(.exclude)').length;
var numPages = Math.ceil(numRows / numPerPage);
var $pager = $('<div id="pager" class="pager"></div>');
for (var page = 0; page < numPages; page++) {
$('<span class="page-number"></span>').text(page + 1).bind('click', {
newPage: page
}, function (event) {
currentPage = event.data['newPage'];
$table.trigger('repaginate');
$(this).addClass('active').siblings().removeClass('active');
}).appendTo($pager).addClass('clickable');
}
// Clear the old pager first
$('#pager').remove();
$pager.insertBefore($table).find('span.page-number:first').addClass('active');
//Clear the old counter
$('#counter').remove();
if (numRows < numPerPage) {
pageCount = numRows;
pageNo = 1;
}
else {
pageCount = currentPage + numPerPage;
pageNo = (numPerPage * currentPage) + 1;
}
var $counter = $('<div id="counter">Showing ' + pageNo + ' to ' + pageCount + ' of ' + numRows + ' Records</div>');
$counter.insertBefore($pager);
});
}
function searchPagingTable(inputVal, tablename, fixedsearch, exclude) {
var table = $(tablename);
table.find('tr:not(.header)').each(function (index, row) {
var allCells = $(row).find('td');
if (allCells.length > 0) {
var found = false;
allCells.each(function (index, td) {
if (fixedsearch == 1 || exclude.length > 0) {
var regExp = new RegExp("\\b" + inputVal + "\\b");
}
else {
var regExp = new RegExp(inputVal, 'i');
}
if (regExp.test($(td).text())) {
found = true;
return false;
}
});
if (exclude.length > 0) {
if (found == true) $(row).hide().addClass('exclude'); else $(row).show().removeClass('exclude');
}
else {
if (found == true) $(row).show().removeClass('exclude'); else $(row).hide().addClass('exclude');
}
}
});
paginate();
}