1 /* Set the defaults for DataTables initialisation */
2 $.extend( true, $.fn.dataTable.defaults, {
4 "<'row'<'col-xs-6'l><'col-xs-6'f>r>"+
6 "<'row'<'col-xs-6'i><'col-xs-6'p>>",
8 "sLengthMenu": "_MENU_ records per page"
13 /* Default class modification */
14 $.extend( $.fn.dataTableExt.oStdClasses, {
15 "sWrapper": "dataTables_wrapper form-inline",
16 "sFilterInput": "form-control input-sm",
17 "sLengthSelect": "form-control input-sm"
20 // In 1.10 we use the pagination renderers to draw the Bootstrap paging,
21 // rather than custom plug-in
22 if ( $.fn.dataTable.Api ) {
23 $.fn.dataTable.defaults.renderer = 'bootstrap';
24 $.fn.dataTable.ext.renderer.pageButton.bootstrap = function ( settings, host, idx, buttons, page, pages ) {
25 var api = new $.fn.dataTable.Api( settings );
26 var classes = settings.oClasses;
27 var lang = settings.oLanguage.oPaginate;
28 var btnDisplay, btnClass;
30 var attach = function( container, buttons ) {
31 var i, ien, node, button;
32 var clickHandler = function ( e ) {
34 if ( e.data.action !== 'ellipsis' ) {
35 api.page( e.data.action ).draw( false );
39 for ( i=0, ien=buttons.length ; i<ien ; i++ ) {
42 if ( $.isArray( button ) ) {
43 attach( container, button );
51 btnDisplay = '…';
52 btnClass = 'disabled';
56 btnDisplay = lang.sFirst;
57 btnClass = button + (page > 0 ?
62 btnDisplay = lang.sPrevious;
63 btnClass = button + (page > 0 ?
68 btnDisplay = lang.sNext;
69 btnClass = button + (page < pages-1 ?
74 btnDisplay = lang.sLast;
75 btnClass = button + (page < pages-1 ?
80 btnDisplay = button + 1;
81 btnClass = page === button ?
88 'class': classes.sPageButton+' '+btnClass,
89 'aria-controls': settings.sTableId,
90 'tabindex': settings.iTabIndex,
91 'id': idx === 0 && typeof button === 'string' ?
92 settings.sTableId +'_'+ button :
100 .appendTo( container );
102 settings.oApi._fnBindAction(
103 node, {action: button}, clickHandler
111 $(host).empty().html('<ul class="pagination"/>').children('ul'),
117 // Integration for 1.9-
118 $.fn.dataTable.defaults.sPaginationType = 'bootstrap';
120 /* API method to get paging information */
121 $.fn.dataTableExt.oApi.fnPagingInfo = function ( oSettings )
124 "iStart": oSettings._iDisplayStart,
125 "iEnd": oSettings.fnDisplayEnd(),
126 "iLength": oSettings._iDisplayLength,
127 "iTotal": oSettings.fnRecordsTotal(),
128 "iFilteredTotal": oSettings.fnRecordsDisplay(),
129 "iPage": oSettings._iDisplayLength === -1 ?
130 0 : Math.ceil( oSettings._iDisplayStart / oSettings._iDisplayLength ),
131 "iTotalPages": oSettings._iDisplayLength === -1 ?
132 0 : Math.ceil( oSettings.fnRecordsDisplay() / oSettings._iDisplayLength )
136 /* Bootstrap style pagination control */
137 $.extend( $.fn.dataTableExt.oPagination, {
139 "fnInit": function( oSettings, nPaging, fnDraw ) {
140 var oLang = oSettings.oLanguage.oPaginate;
141 var fnClickHandler = function ( e ) {
143 if ( oSettings.oApi._fnPageChange(oSettings, e.data.action) ) {
149 '<ul class="pagination">'+
150 '<li class="prev disabled"><a href="#">← '+oLang.sPrevious+'</a></li>'+
151 '<li class="next disabled"><a href="#">'+oLang.sNext+' → </a></li>'+
154 var els = $('a', nPaging);
155 $(els[0]).bind( 'click.DT', { action: "previous" }, fnClickHandler );
156 $(els[1]).bind( 'click.DT', { action: "next" }, fnClickHandler );
159 "fnUpdate": function ( oSettings, fnDraw ) {
161 var oPaging = oSettings.oInstance.fnPagingInfo();
162 var an = oSettings.aanFeatures.p;
163 var i, ien, j, sClass, iStart, iEnd, iHalf=Math.floor(iListLength/2);
165 if ( oPaging.iTotalPages < iListLength) {
167 iEnd = oPaging.iTotalPages;
169 else if ( oPaging.iPage <= iHalf ) {
172 } else if ( oPaging.iPage >= (oPaging.iTotalPages-iHalf) ) {
173 iStart = oPaging.iTotalPages - iListLength + 1;
174 iEnd = oPaging.iTotalPages;
176 iStart = oPaging.iPage - iHalf + 1;
177 iEnd = iStart + iListLength - 1;
180 for ( i=0, ien=an.length ; i<ien ; i++ ) {
181 // Remove the middle elements
182 $('li:gt(0)', an[i]).filter(':not(:last)').remove();
184 // Add the new list items and their event handlers
185 for ( j=iStart ; j<=iEnd ; j++ ) {
186 sClass = (j==oPaging.iPage+1) ? 'class="active"' : '';
187 $('<li '+sClass+'><a href="#">'+j+'</a></li>')
188 .insertBefore( $('li:last', an[i])[0] )
189 .bind('click', function (e) {
191 oSettings._iDisplayStart = (parseInt($('a', this).text(),10)-1) * oPaging.iLength;
196 // Add / remove disabled classes from the static elements
197 if ( oPaging.iPage === 0 ) {
198 $('li:first', an[i]).addClass('disabled');
200 $('li:first', an[i]).removeClass('disabled');
203 if ( oPaging.iPage === oPaging.iTotalPages-1 || oPaging.iTotalPages === 0 ) {
204 $('li:last', an[i]).addClass('disabled');
206 $('li:last', an[i]).removeClass('disabled');
216 * TableTools Bootstrap compatibility
217 * Required TableTools 2.1+
219 if ( $.fn.DataTable.TableTools ) {
220 // Set the classes that TableTools uses to something suitable for Bootstrap
221 $.extend( true, $.fn.DataTable.TableTools.classes, {
222 "container": "DTTT btn-group",
224 "normal": "btn btn-default",
225 "disabled": "disabled"
228 "container": "DTTT_dropdown dropdown-menu",
231 "disabled": "disabled"
235 "info": "DTTT_print_info modal"
242 // Have the collection use a bootstrap compatible dropdown
243 $.extend( true, $.fn.DataTable.TableTools.DEFAULTS.oTags, {