mirror of
https://github.com/Mottie/tablesorter.git
synced 2025-01-12 15:24:21 +00:00
Merge pull request #711 from camallen/slow_page_number_links
Pager widget - slow table update when there are a large number of page number links
This commit is contained in:
commit
43d80b64be
@ -65,6 +65,9 @@
|
|||||||
// Number of visible rows
|
// Number of visible rows
|
||||||
size: 10,
|
size: 10,
|
||||||
|
|
||||||
|
// Number of options to include in the pager number selector
|
||||||
|
maxOptionSize: 20,
|
||||||
|
|
||||||
// Save pager page & size if the storage script is loaded (requires $.tablesorter.storage in jquery.tablesorter.widgets.js)
|
// Save pager page & size if the storage script is loaded (requires $.tablesorter.storage in jquery.tablesorter.widgets.js)
|
||||||
savePages: true,
|
savePages: true,
|
||||||
|
|
||||||
@ -186,11 +189,37 @@
|
|||||||
if ( p.$goto.length ) {
|
if ( p.$goto.length ) {
|
||||||
t = '';
|
t = '';
|
||||||
pg = Math.min( p.totalPages, p.filteredPages );
|
pg = Math.min( p.totalPages, p.filteredPages );
|
||||||
for ( i = 1; i <= pg; i++ ) {
|
// Filter the options page number link array if it's larger than 'maxOptionSize'
|
||||||
t += '<option>' + i + '</option>';
|
// as large page set links will slow the browser on large dom inserts
|
||||||
|
skip_set_size = Math.floor(pg / p.maxOptionSize),
|
||||||
|
large_collection = pg > p.maxOptionSize,
|
||||||
|
current_page = p.page + 1,
|
||||||
|
start_page = 1,
|
||||||
|
end_page = pg,
|
||||||
|
option_pages = [];
|
||||||
|
//construct default options pages array
|
||||||
|
var option_pages_start_page = (large_collection && current_page == 1) ? skip_set_size : 1
|
||||||
|
for (i = option_pages_start_page; i <= pg;) {
|
||||||
|
option_pages.push(i);
|
||||||
|
(large_collection) ? i = i+skip_set_size : i++;
|
||||||
|
}
|
||||||
|
if (large_collection) {
|
||||||
|
var central_focus_size = Math.floor(p.maxOptionSize / 2) - 1,
|
||||||
|
lower_focus_window = Math.abs(Math.floor(current_page - central_focus_size/2)),
|
||||||
|
focus_option_pages = [];
|
||||||
|
start_page = Math.min(current_page, lower_focus_window);
|
||||||
|
end_page = start_page + central_focus_size;
|
||||||
|
//construct an array to get a focus set around the current page
|
||||||
|
for (i = start_page; i <= end_page ; i++) focus_option_pages.push(i);
|
||||||
|
var insert_index = Math.floor(option_pages.length / 2) - Math.floor(focus_option_pages.length / 2);
|
||||||
|
Array.prototype.splice.apply(option_pages, [ insert_index, focus_option_pages.length ].concat(focus_option_pages));
|
||||||
|
option_pages.sort(function sortNumber(a,b) { return a - b; });
|
||||||
|
}
|
||||||
|
for ( i = 0; i < option_pages.length; i++) {
|
||||||
|
t += '<option>' + option_pages[i] + '</option>';
|
||||||
}
|
}
|
||||||
p.$goto[0].innerHTML = t;
|
p.$goto[0].innerHTML = t;
|
||||||
p.$goto[0].value = p.page + 1;
|
p.$goto[0].value = current_page;
|
||||||
}
|
}
|
||||||
// rebind startRow/page inputs
|
// rebind startRow/page inputs
|
||||||
$out.find('.ts-startRow, .ts-page').unbind('change').bind('change', function(){
|
$out.find('.ts-startRow, .ts-page').unbind('change').bind('change', function(){
|
||||||
|
Loading…
Reference in New Issue
Block a user