2 * Copyright 2016 ZTE, Inc. and others.
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
17 $.fn.dataTableExt.oApi.fnPagingInfo = function (oSettings) {
\r
19 "iEnd": oSettings.fnDisplayEnd(),
\r
20 "iLength": oSettings._iDisplayLength,
\r
21 "iTotal": oSettings.fnRecordsTotal(),
\r
22 "iFilteredTotal": oSettings.fnRecordsDisplay(),
\r
23 "iPage": Math.ceil(oSettings._iDisplayStart / oSettings._iDisplayLength),
\r
24 "iTotalPages": Math.ceil(oSettings.fnRecordsDisplay() / oSettings._iDisplayLength)
\r
28 $.extend($.fn.dataTableExt.oPagination, {
\r
29 "bootstrap_extended": {
\r
30 "fnInit": function (oSettings, nPaging, fnDraw) {
\r
31 var oLang = oSettings.oLanguage.oPaginate;
\r
32 var oPaging = oSettings.oInstance.fnPagingInfo();
\r
34 var fnClickHandler = function (e) {
\r
36 if (oSettings.oApi._fnPageChange(oSettings, e.data.action)) {
\r
42 '<div class="pagination-panel"> ' + oLang.sPage + ' ' +
\r
43 '<a href="#" class="btn btn-sm default prev disabled" title="' + oLang.sPrevious + '"><i class="fa fa-angle-left"></i></a>' +
\r
44 '<input type="text" class="pagination-panel-input input-mini input-inline input-sm" maxlenght="5" style="text-align:center; margin: 0 4px; border: 1px solid rgb(169, 169, 169);height: 28px;">' +
\r
45 '<a href="#" class="btn btn-sm default next disabled" title="' + oLang.sNext + '"><i class="fa fa-angle-right"></i></a> ' +
\r
46 oLang.sPageOf + ' <span class="pagination-panel-total"></span>' +
\r
50 var els = $('a', nPaging);
\r
52 $(els[0]).bind('click.DT', {action: "previous"}, fnClickHandler);
\r
53 $(els[1]).bind('click.DT', {action: "next"}, fnClickHandler);
\r
55 $('.pagination-panel-input', nPaging).bind('change.DT', function (e) {
\r
56 var oPaging = oSettings.oInstance.fnPagingInfo();
\r
58 var page = parseInt($(this).val());
\r
59 if (page > 0 && page < oPaging.iTotalPages) {
\r
60 if (oSettings.oApi._fnPageChange(oSettings, page - 1)) {
\r
64 $(this).val(oPaging.iPage + 1);
\r
68 $('.pagination-panel-input', nPaging).bind('keypress.DT', function (e) {
\r
69 var oPaging = oSettings.oInstance.fnPagingInfo();
\r
70 if (e.which == 13) {
\r
71 var page = parseInt($(this).val());
\r
72 if (page > 0 && page < oSettings.oInstance.fnPagingInfo().iTotalPages) {
\r
73 if (oSettings.oApi._fnPageChange(oSettings, page - 1)) {
\r
77 $(this).val(oPaging.iPage + 1);
\r
84 "fnUpdate": function (oSettings, fnDraw) {
\r
85 var iListLength = 5;
\r
86 var oPaging = oSettings.oInstance.fnPagingInfo();
\r
87 var an = oSettings.aanFeatures.p;
\r
88 var i, j, sClass, iStart, iEnd, iHalf = Math.floor(iListLength / 2);
\r
90 if (oPaging.iTotalPages < iListLength) {
\r
92 iEnd = oPaging.iTotalPages;
\r
94 else if (oPaging.iPage <= iHalf) {
\r
97 } else if (oPaging.iPage >= (oPaging.iTotalPages - iHalf)) {
\r
98 iStart = oPaging.iTotalPages - iListLength + 1;
\r
99 iEnd = oPaging.iTotalPages;
\r
101 iStart = oPaging.iPage - iHalf + 1;
\r
102 iEnd = iStart + iListLength - 1;
\r
106 for (i = 0, iLen = an.length; i < iLen; i++) {
\r
107 var wrapper = $(an[i]).parents(".dataTables_wrapper");
\r
109 if (oPaging.iTotalPages <= 0) {
\r
110 $('.pagination-panel, .dataTables_length', wrapper).hide();
\r
112 $('.pagination-panel, .dataTables_length', wrapper).show();
\r
115 $('.pagination-panel-total', an[i]).html(oPaging.iTotalPages);
\r
116 $('.pagination-panel-input', an[i]).val(oPaging.iPage + 1);
\r
118 // Remove the middle elements
\r
119 $('li:gt(1)', an[i]).filter(':not(.next)').remove();
\r
121 // Add the new list items and their event handlers
\r
122 for (j = iStart; j <= iEnd; j++) {
\r
123 sClass = (j == oPaging.iPage + 1) ? 'class="active"' : '';
\r
124 $('<li ' + sClass + '><a href="#">' + j + '</a></li>')
\r
125 .insertBefore($('li.next:first', an[i])[0])
\r
126 .bind('click', function (e) {
\r
127 e.preventDefault();
\r
128 oSettings._iDisplayStart = (parseInt($('a', this).text(), 10) - 1) * oPaging.iLength;
\r
133 // Add / remove disabled classes from the static elements
\r
134 if (oPaging.iPage === 0) {
\r
135 $('a.prev', an[i]).addClass('disabled');
\r
137 $('a.prev', an[i]).removeClass('disabled');
\r
140 if (oPaging.iPage === oPaging.iTotalPages - 1 || oPaging.iTotalPages === 0) {
\r
141 $('a.next', an[i]).addClass('disabled');
\r
143 $('a.next', an[i]).removeClass('disabled');
\r