Skip to content

Commit 29f6c7b

Browse files
Version 1.0.1
1 parent 7566575 commit 29f6c7b

File tree

4 files changed

+60
-23
lines changed

4 files changed

+60
-23
lines changed

dist/jquery.tablePagination.js

Lines changed: 51 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
* jQuery tablePagination Plugin
33
* https://github.com/Reload-Lab/jquery-tablePagination
44
*
5-
* @updated September 21, 2023
6-
* @version 1.0.0
5+
* @updated September 22, 2023
6+
* @version 1.0.1
77
*
88
* @author Domenico Gigante <domenico.gigante@reloadlab.it>
99
* @copyright (c) 2023 Reload Laboratorio Multimediale <info@reloadlab.it> (https://www.reloadlab.it)
@@ -54,7 +54,9 @@
5454
selectNumRowsPage: true, // Select enabled
5555
selectOptions: [10, 25, 50, 100, 'Tutte'], // Select options
5656
selectTitle: 'Numero di righe per pagina', // Select title attribute
57-
useHash: true // use hashchange event and back button
57+
useHash: true, // use hashchange event and back button
58+
onPage: null, // function call on change page
59+
onSelect: null // function call on select num rows per page
5860
}, arguments[0]);
5961
}
6062

@@ -234,10 +236,11 @@
234236
if(!$(this).hasClass(DISABLED_CLASS)){
235237

236238
// Set new current page
237-
var newPage,
238-
state = {};
239-
var actualPage = $ctrl.find('.' + LI_CLASS + '.' + ACTIVE_CLASS);
240-
if((newPage = parseInt(actualPage.attr('data-tp-num')) - 2) >= 0){
239+
var state = {},
240+
actualPage = $ctrl.find('.' + LI_CLASS + '.' + ACTIVE_CLASS)
241+
.attr('data-tp-num'),
242+
newPage = parseInt(actualPage) - 2;
243+
if(newPage >= 0){
241244

242245
options.currentPage = newPage;
243246

@@ -254,6 +257,13 @@
254257

255258
// Trig event
256259
$table.trigger('paginate');
260+
261+
// If onPage function exists...
262+
if(typeof options.onPage === 'function'){
263+
264+
// Execute onPage function
265+
options.onPage($table, actualPage, (newPage + 1));
266+
}
257267
}
258268
})
259269
.appendTo($ctrl);
@@ -274,11 +284,13 @@
274284
// Set new current page
275285
if(!$(this).hasClass(DISABLED_CLASS)){
276286

277-
var newPage,
278-
state = {};
279-
if((newPage = parseInt($(this).attr('data-tp-num')) - 1) >= 0){
287+
var state = {},
288+
actualPage = $ctrl.find('.' + LI_CLASS + '.' + ACTIVE_CLASS)
289+
.attr('data-tp-num'),
290+
newPage = parseInt($(this).attr('data-tp-num')) - 1;
291+
if(newPage >= 0){
280292

281-
options.currentPage = state[id] = newPage;
293+
options.currentPage = newPage;
282294

283295
// Set the state
284296
if(options.useHash){
@@ -293,6 +305,13 @@
293305

294306
// Trig event
295307
$table.trigger('paginate');
308+
309+
// If onPage function exists...
310+
if(typeof options.onPage === 'function'){
311+
312+
// Execute onPage function
313+
options.onPage($table, actualPage, (newPage + 1));
314+
}
296315
}
297316
})
298317
.appendTo($ctrl);
@@ -311,10 +330,11 @@
311330
if(!$(this).hasClass(DISABLED_CLASS)){
312331

313332
// Set new current page
314-
var newPage,
315-
state = {};
316-
var actualPage = $ctrl.find('.' + LI_CLASS + '.' + ACTIVE_CLASS);
317-
if((newPage = parseInt(actualPage.attr('data-tp-num'))) < options.numPages){
333+
var state = {},
334+
actualPage = $ctrl.find('.' + LI_CLASS + '.' + ACTIVE_CLASS)
335+
.attr('data-tp-num'),
336+
newPage = parseInt(actualPage);
337+
if(newPage < options.numPages){
318338

319339
options.currentPage = state[id] = newPage;
320340

@@ -328,10 +348,17 @@
328348
// Set configuration in data attribute
329349
$table.data('tp', $.extend({}, options));
330350
}
331-
}
332351

333-
// Trig event
334-
$table.trigger('paginate');
352+
// Trig event
353+
$table.trigger('paginate');
354+
355+
// If onPage function exists...
356+
if(typeof options.onPage === 'function'){
357+
358+
// Execute onPage function
359+
options.onPage($table, actualPage, (newPage + 1));
360+
}
361+
}
335362
})
336363
.appendTo($ctrl);
337364

@@ -516,6 +543,12 @@
516543
// Call load
517544
that._load();
518545

546+
// If onSelect function exists...
547+
if(typeof options.onSelect === 'function'){
548+
549+
// Execute onSelect function
550+
options.onSelect($table, $(this).val());
551+
}
519552
}).appendTo($selecter);
520553

521554
// Create options

dist/jquery.tablePagination.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/index.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47798,7 +47798,11 @@ <h1>Elenco comuni italiani</h1>
4779847798
$(document).ready(function(){
4779947799

4780047800
var options = {
47801-
numRowsPage: 25
47801+
numRowsPage: 25,
47802+
/*onPage: function($table, from, to){
47803+
47804+
console.log(from + ' ' + to);
47805+
}*/
4780247806
//useHash: false,
4780347807
//selectNumRowsPage: false,
4780447808
//countPages: false

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jquery-tablepagination",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "Simple tables pagination solution for use with jQuery and Bootstrap 4",
55
"keywords": [
66
"jquery",

0 commit comments

Comments
 (0)