You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
2.4 KiB
JavaScript
70 lines
2.4 KiB
JavaScript
10 years ago
|
/**
|
||
|
* @summary ConditionalPagination
|
||
|
* @description Hide pagination controls when the amount of pages is <= 1
|
||
|
* @version 1.0.0
|
||
|
* @file dataTables.conditionalPagination.js
|
||
|
* @author Matthew Hasbach (https://github.com/mjhasbach)
|
||
|
* @contact hasbach.git@gmail.com
|
||
|
* @copyright Copyright 2015 Matthew Hasbach
|
||
|
*
|
||
|
* License MIT - http://datatables.net/license/mit
|
||
|
*
|
||
|
* This feature plugin for DataTables hides pagination controls when the amount
|
||
|
* of pages is <= 1. The controls can either appear / disappear or fade in / out
|
||
|
*
|
||
|
* @example
|
||
|
* $('#myTable').DataTable({
|
||
|
* conditionalPagination: {
|
||
|
* enable: true,
|
||
|
* fade: {
|
||
|
* enable: true,
|
||
|
* speed: 'fast'
|
||
|
* }
|
||
|
* }
|
||
|
* });
|
||
|
*/
|
||
|
|
||
|
(function(window, document, $) {
|
||
|
$(document).on('init.dt', function(e, settings) {
|
||
|
if ($.isPlainObject(settings.oInit.conditionalPagination) && settings.oInit.conditionalPagination.enable) {
|
||
|
var api = new $.fn.dataTable.Api(settings),
|
||
|
fade = settings.oInit.conditionalPagination.fade,
|
||
|
fadeSpeed = 'slow',
|
||
|
fadeEnable = false,
|
||
|
conditionalPagination = function() {
|
||
|
var $pagination = $(api.table().container()).find('div.dataTables_paginate');
|
||
|
|
||
|
if (api.page.info().pages <= 1) {
|
||
|
if (fadeEnable) {
|
||
|
$pagination.stop().fadeOut(fadeSpeed);
|
||
|
}
|
||
|
else {
|
||
|
$pagination.hide();
|
||
|
}
|
||
|
}
|
||
|
else {
|
||
|
if (fadeEnable) {
|
||
|
$pagination.stop().fadeIn(fadeSpeed);
|
||
|
}
|
||
|
else {
|
||
|
$pagination.show();
|
||
|
}
|
||
|
}
|
||
|
};
|
||
|
|
||
|
if ($.isPlainObject(fade)) {
|
||
|
if (fade.enable === true) {
|
||
|
fadeEnable = true;
|
||
|
}
|
||
|
|
||
|
if ($.isNumeric(fade.speed) || $.type(fade.speed) === 'string') {
|
||
|
fadeSpeed = fade.speed;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
conditionalPagination();
|
||
|
|
||
|
api.on('draw.dt', conditionalPagination);
|
||
|
}
|
||
|
});
|
||
|
})(window, document, jQuery);
|