1 /* Set the defaults for DataTables initialisation */
2 $.extend(true, $.fn.dataTable.defaults, {
3 "sDom": "<'row'<'col-sm-6'l><'col-sm-6'f>r>" + "t" + "<'row'<'col-sm-6'i><'col-sm-6'p>>",
5 "sLengthMenu": "_MENU_ records per page"
10 /* Default class modification */
11 $.extend($.fn.dataTableExt.oStdClasses, {
12 "sWrapper": "dataTables_wrapper form-inline",
13 "sFilterInput": "form-control input-sm",
14 "sLengthSelect": "form-control input-sm"
17 // In 1.10 we use the pagination renderers to draw the Bootstrap paging,
18 // rather than custom plug-in
19 if ($.fn.dataTable.Api) {
20 $.fn.dataTable.defaults.renderer = 'bootstrap';
21 $.fn.dataTable.ext.renderer.pageButton.bootstrap = function(settings, host, idx, buttons, page, pages) {
22 var api = new $.fn.dataTable.Api(settings);
23 var classes = settings.oClasses;
24 var lang = settings.oLanguage.oPaginate;
25 var btnDisplay, btnClass;
27 var attach = function(container, buttons) {
28 var i, ien, node, button;
29 var clickHandler = function(e) {
31 if (e.data.action !== 'ellipsis') {
32 api.page(e.data.action).draw(false);
36 for (i = 0, ien = buttons.length; i < ien; i++) {
39 if ($.isArray(button)) {
40 attach(container, button);
47 btnDisplay = '…';
48 btnClass = 'disabled';
52 btnDisplay = lang.sFirst;
53 btnClass = button + (page > 0 ?
58 btnDisplay = lang.sPrevious;
59 btnClass = button + (page > 0 ?
64 btnDisplay = lang.sNext;
65 btnClass = button + (page < pages - 1 ?
70 btnDisplay = lang.sLast;
71 btnClass = button + (page < pages - 1 ?
76 btnDisplay = button + 1;
77 btnClass = page === button ?
84 'class': classes.sPageButton + ' ' + btnClass,
85 'aria-controls': settings.sTableId,
86 'tabindex': settings.iTabIndex,
87 'id': idx === 0 && typeof button === 'string' ? settings.sTableId + '_' + button : null
96 settings.oApi._fnBindAction(
107 $(host).empty().html('<ul class="pagination"/>').children('ul'),
112 // Integration for 1.9-
113 $.fn.dataTable.defaults.sPaginationType = 'bootstrap';
115 /* API method to get paging information */
116 $.fn.dataTableExt.oApi.fnPagingInfo = function(oSettings) {
118 "iStart": oSettings._iDisplayStart,
119 "iEnd": oSettings.fnDisplayEnd(),
120 "iLength": oSettings._iDisplayLength,
121 "iTotal": oSettings.fnRecordsTotal(),
122 "iFilteredTotal": oSettings.fnRecordsDisplay(),
123 "iPage": oSettings._iDisplayLength === -1 ? 0 : Math.ceil(oSettings._iDisplayStart / oSettings._iDisplayLength),
124 "iTotalPages": oSettings._iDisplayLength === -1 ? 0 : Math.ceil(oSettings.fnRecordsDisplay() / oSettings._iDisplayLength)
128 /* Bootstrap style pagination control */
129 $.extend($.fn.dataTableExt.oPagination, {
131 "fnInit": function(oSettings, nPaging, fnDraw) {
132 var oLang = oSettings.oLanguage.oPaginate;
133 var fnClickHandler = function(e) {
135 if (oSettings.oApi._fnPageChange(oSettings, e.data.action)) {
141 '<ul class="pagination">' +
142 '<li class="prev disabled"><a href="#">← ' + oLang.sPrevious + '</a></li>' +
143 '<li class="next disabled"><a href="#">' + oLang.sNext + ' → </a></li>' +
146 var els = $('a', nPaging);
147 $(els[0]).bind('click.DT', {
150 $(els[1]).bind('click.DT', {
155 "fnUpdate": function(oSettings, fnDraw) {
157 var oPaging = oSettings.oInstance.fnPagingInfo();
158 var an = oSettings.aanFeatures.p;
159 var i, ien, j, sClass, iStart, iEnd, iHalf = Math.floor(iListLength / 2);
161 if (oPaging.iTotalPages < iListLength) {
163 iEnd = oPaging.iTotalPages;
164 } else if (oPaging.iPage <= iHalf) {
167 } else if (oPaging.iPage >= (oPaging.iTotalPages - iHalf)) {
168 iStart = oPaging.iTotalPages - iListLength + 1;
169 iEnd = oPaging.iTotalPages;
171 iStart = oPaging.iPage - iHalf + 1;
172 iEnd = iStart + iListLength - 1;
175 for (i = 0, ien = an.length; i < ien; i++) {
176 // Remove the middle elements
177 $('li:gt(0)', an[i]).filter(':not(:last)').remove();
179 // Add the new list items and their event handlers
180 for (j = iStart; j <= iEnd; j++) {
181 sClass = (j == oPaging.iPage + 1) ? 'class="active"' : '';
182 $('<li ' + sClass + '><a href="#">' + j + '</a></li>')
183 .insertBefore($('li:last', an[i])[0])
184 .bind('click', function(e) {
186 oSettings._iDisplayStart = (parseInt($('a', this).text(), 10) - 1) * oPaging.iLength;
191 // Add / remove disabled classes from the static elements
192 if (oPaging.iPage === 0) {
193 $('li:first', an[i]).addClass('disabled');
195 $('li:first', an[i]).removeClass('disabled');
198 if (oPaging.iPage === oPaging.iTotalPages - 1 || oPaging.iTotalPages === 0) {
199 $('li:last', an[i]).addClass('disabled');
201 $('li:last', an[i]).removeClass('disabled');
211 * TableTools Bootstrap compatibility
212 * Required TableTools 2.1+
214 if ($.fn.DataTable.TableTools) {
215 // Set the classes that TableTools uses to something suitable for Bootstrap
216 $.extend(true, $.fn.DataTable.TableTools.classes, {
217 "container": "DTTT btn-group",
219 "normal": "btn btn-default",
220 "disabled": "disabled"
223 "container": "DTTT_dropdown dropdown-menu",
226 "disabled": "disabled"
230 "info": "DTTT_print_info modal"
237 // Have the collection use a bootstrap compatible dropdown
238 $.extend(true, $.fn.DataTable.TableTools.DEFAULTS.oTags, {