我有一个在正常事件下正常工作的分页脚本。即没有ajax调用等。我正在做的是执行搜索,当显示结果时,分页没有得到更新。我需要做的是当搜索结束并且显示结果时,更新页面的数量以反映搜索的结果。例如,如果有1个结果只显示1页。如果有10个结果,则根据结果更新paes的数量。
如果有人可以帮助我,我将不胜感激。非常感谢
js code
try:
raise KeyError('some error message')
except KeyError as e:
print (str(e))
print ('some error message')
print (str(e) == 'some error message')
按钮搜索js
$(function() {
$('table.paginated').each(function() {
var currentPage = 0;
var numPerPage = 8;
var $table = $(this);
var numRows = $table.find('tbody tr').length;
var numPages = Math.ceil(numRows / numPerPage);
var $pager1 = $('<div class="pager"></div>');
var $pager2 = "";
var $numberPicker = $('<div class="numberPicker"></div>');
var dropdown = $('<select class="options"></select>');
var dropdown2 = "";
$table.bind('repaginate', function() {
$table.find('tbody tr').hide().slice(currentPage * numPerPage, (currentPage + 1) * numPerPage).show();
});
$table.trigger('repaginate');
function rePage(numPages) {
$('.page-number').remove();
for (var page = 0; page < numPages; page++) {
$('<span class="page-number"></span>').text(page + 1).bind('click', {
newPage: page
}, function(event) {
var selected = $(this).index();
var selected2 = ($(this).index()) + numPages;
currentPage = event.data['newPage'];
$table.trigger('repaginate');
$('span.page-number').removeClass('active');
$("span.page-number").each(function(index) {
if (index === selected) {
$(this).addClass('active');
$("span.page-number:eq(" + selected2 + ")").addClass('active')
}
});
}).appendTo($pager1).addClass('clickable');
}
$pager2 = $pager1.clone(true);
$pager2.insertAfter($table);
}
rePage(numPages);
$pager1.insertBefore($table);
$pager2.insertAfter($table);
$('span.page-number:first-child').addClass('active');
$([5, numPerPage, 10, 20]).each(function() {
var $num = this;
$('<option></option>').text(this).attr('value', this).appendTo(dropdown);
});
dropdown.bind('change', function() {
var oldNumPerPage = numPerPage;
numPerPage = this.value;
numPages = Math.ceil(numRows / numPerPage);
$table.trigger('repaginate');
rePage(numPages);
currentPage = Math.ceil((currentPage * oldNumPerPage) / numPerPage);
$("span.page-number:eq(" + currentPage + ")").trigger('click');
$('.options').val(numPerPage);
$('.options2').val(numPerPage);
}).insertBefore($pager2);
dropdown2 = dropdown.clone(true);
dropdown2.addClass('options2');
dropdown2.insertAfter($pager1);
$('.options').val(numPerPage);
$('.options2').val(numPerPage);
});
});