1 /* Set the defaults for DataTables initialisation */
2 $.extend( true, $.fn.dataTable.defaults, {
3 "sDom": "<'row'<'col-xs-6'l><'col-xs-6'f>r>t<'row'<'col-xs-6'i><'col-xs-6'p>>",
4 "sPaginationType": "bootstrap",
6 "sLengthMenu": "_MENU_ records per page"
13 /* Default class modification */
14 $.extend( $.fn.dataTableExt.oStdClasses, {
15 "sWrapper": "dataTables_wrapper form-inline"
19 /* API method to get paging information */
20 $.fn.dataTableExt.oApi.fnPagingInfo = function ( oSettings )
23 "iStart": oSettings._iDisplayStart,
24 "iEnd": oSettings.fnDisplayEnd(),
25 "iLength": oSettings._iDisplayLength,
26 "iTotal": oSettings.fnRecordsTotal(),
27 "iFilteredTotal": oSettings.fnRecordsDisplay(),
28 "iPage": oSettings._iDisplayLength === -1 ?
29 0 : Math.ceil( oSettings._iDisplayStart / oSettings._iDisplayLength ),
30 "iTotalPages": oSettings._iDisplayLength === -1 ?
31 0 : Math.ceil( oSettings.fnRecordsDisplay() / oSettings._iDisplayLength )
36 /* Bootstrap style pagination control */
37 $.extend( $.fn.dataTableExt.oPagination, {
39 "fnInit": function( oSettings, nPaging, fnDraw ) {
40 var oLang = oSettings.oLanguage.oPaginate;
41 var fnClickHandler = function ( e ) {
43 if ( oSettings.oApi._fnPageChange(oSettings, e.data.action) ) {
49 '<ul class="pagination">'+
50 '<li class="prev disabled"><a href="#">← '+oLang.sPrevious+'</a></li>'+
51 '<li class="next disabled"><a href="#">'+oLang.sNext+' → </a></li>'+
54 var els = $('a', nPaging);
55 $(els[0]).bind( 'click.DT', { action: "previous" }, fnClickHandler );
56 $(els[1]).bind( 'click.DT', { action: "next" }, fnClickHandler );
59 "fnUpdate": function ( oSettings, fnDraw ) {
61 var oPaging = oSettings.oInstance.fnPagingInfo();
62 var an = oSettings.aanFeatures.p;
63 var i, ien, j, sClass, iStart, iEnd, iHalf=Math.floor(iListLength/2);
65 if ( oPaging.iTotalPages < iListLength) {
67 iEnd = oPaging.iTotalPages;
69 else if ( oPaging.iPage <= iHalf ) {
72 } else if ( oPaging.iPage >= (oPaging.iTotalPages-iHalf) ) {
73 iStart = oPaging.iTotalPages - iListLength + 1;
74 iEnd = oPaging.iTotalPages;
76 iStart = oPaging.iPage - iHalf + 1;
77 iEnd = iStart + iListLength - 1;
80 for ( i=0, ien=an.length ; i<ien ; i++ ) {
81 // Remove the middle elements
82 $('li:gt(0)', an[i]).filter(':not(:last)').remove();
84 // Add the new list items and their event handlers
85 for ( j=iStart ; j<=iEnd ; j++ ) {
86 sClass = (j==oPaging.iPage+1) ? 'class="active"' : '';
87 $('<li '+sClass+'><a href="#">'+j+'</a></li>')
88 .insertBefore( $('li:last', an[i])[0] )
89 .bind('click', function (e) {
91 oSettings._iDisplayStart = (parseInt($('a', this).text(),10)-1) * oPaging.iLength;
96 // Add / remove disabled classes from the static elements
97 if ( oPaging.iPage === 0 ) {
98 $('li:first', an[i]).addClass('disabled');
100 $('li:first', an[i]).removeClass('disabled');
103 if ( oPaging.iPage === oPaging.iTotalPages-1 || oPaging.iTotalPages === 0 ) {
104 $('li:last', an[i]).addClass('disabled');
106 $('li:last', an[i]).removeClass('disabled');
115 * TableTools Bootstrap compatibility
116 * Required TableTools 2.1+
118 if ( $.fn.DataTable.TableTools ) {
119 // Set the classes that TableTools uses to something suitable for Bootstrap
120 $.extend( true, $.fn.DataTable.TableTools.classes, {
121 "container": "DTTT btn-group",
123 "normal": "btn btn-default",
124 "disabled": "disabled"
127 "container": "DTTT_dropdown dropdown-menu",
130 "disabled": "disabled"
134 "info": "DTTT_print_info modal"
141 // Have the collection use a bootstrap compatible dropdown
142 $.extend( true, $.fn.DataTable.TableTools.DEFAULTS.oTags, {