|
2 | 2 | * jQuery tablePagination Plugin
|
3 | 3 | * https://github.com/Reload-Lab/jquery-tablePagination
|
4 | 4 | *
|
5 |
| - * @updated September 21, 2023 |
6 |
| - * @version 1.0.0 |
| 5 | + * @updated September 22, 2023 |
| 6 | + * @version 1.0.1 |
7 | 7 | *
|
8 | 8 | * @author Domenico Gigante <domenico.gigante@reloadlab.it>
|
9 | 9 | * @copyright (c) 2023 Reload Laboratorio Multimediale <info@reloadlab.it> (https://www.reloadlab.it)
|
|
54 | 54 | selectNumRowsPage: true, // Select enabled
|
55 | 55 | selectOptions: [10, 25, 50, 100, 'Tutte'], // Select options
|
56 | 56 | 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 |
58 | 60 | }, arguments[0]);
|
59 | 61 | }
|
60 | 62 |
|
|
234 | 236 | if(!$(this).hasClass(DISABLED_CLASS)){
|
235 | 237 |
|
236 | 238 | // 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){ |
241 | 244 |
|
242 | 245 | options.currentPage = newPage;
|
243 | 246 |
|
|
254 | 257 |
|
255 | 258 | // Trig event
|
256 | 259 | $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 | + } |
257 | 267 | }
|
258 | 268 | })
|
259 | 269 | .appendTo($ctrl);
|
|
274 | 284 | // Set new current page
|
275 | 285 | if(!$(this).hasClass(DISABLED_CLASS)){
|
276 | 286 |
|
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){ |
280 | 292 |
|
281 |
| - options.currentPage = state[id] = newPage; |
| 293 | + options.currentPage = newPage; |
282 | 294 |
|
283 | 295 | // Set the state
|
284 | 296 | if(options.useHash){
|
|
293 | 305 |
|
294 | 306 | // Trig event
|
295 | 307 | $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 | + } |
296 | 315 | }
|
297 | 316 | })
|
298 | 317 | .appendTo($ctrl);
|
|
311 | 330 | if(!$(this).hasClass(DISABLED_CLASS)){
|
312 | 331 |
|
313 | 332 | // 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){ |
318 | 338 |
|
319 | 339 | options.currentPage = state[id] = newPage;
|
320 | 340 |
|
|
328 | 348 | // Set configuration in data attribute
|
329 | 349 | $table.data('tp', $.extend({}, options));
|
330 | 350 | }
|
331 |
| - } |
332 | 351 |
|
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 | + } |
335 | 362 | })
|
336 | 363 | .appendTo($ctrl);
|
337 | 364 |
|
|
516 | 543 | // Call load
|
517 | 544 | that._load();
|
518 | 545 |
|
| 546 | + // If onSelect function exists... |
| 547 | + if(typeof options.onSelect === 'function'){ |
| 548 | + |
| 549 | + // Execute onSelect function |
| 550 | + options.onSelect($table, $(this).val()); |
| 551 | + } |
519 | 552 | }).appendTo($selecter);
|
520 | 553 |
|
521 | 554 | // Create options
|
|
0 commit comments