1+ /* Set the defaults for DataTables initialisation */
2+ $ . extend ( true , $ . fn . dataTable . defaults , {
3+ "sDom" : "<'row-fluid'<'span6'l><'span6'f>r>t<'row-fluid'<'span6'i><'span6'p>>" ,
4+ "sPaginationType" : "bootstrap" ,
5+ "oLanguage" : {
6+ "sLengthMenu" : "_MENU_ records per page"
7+ }
8+ } ) ;
9+
10+
111/* Default class modification */
212$ . extend ( $ . fn . dataTableExt . oStdClasses , {
313 "sWrapper" : "dataTables_wrapper form-inline"
414} ) ;
515
16+
617/* API method to get paging information */
718$ . fn . dataTableExt . oApi . fnPagingInfo = function ( oSettings )
819{
@@ -12,10 +23,13 @@ $.fn.dataTableExt.oApi.fnPagingInfo = function ( oSettings )
1223 "iLength" : oSettings . _iDisplayLength ,
1324 "iTotal" : oSettings . fnRecordsTotal ( ) ,
1425 "iFilteredTotal" : oSettings . fnRecordsDisplay ( ) ,
15- "iPage" : Math . ceil ( oSettings . _iDisplayStart / oSettings . _iDisplayLength ) ,
16- "iTotalPages" : Math . ceil ( oSettings . fnRecordsDisplay ( ) / oSettings . _iDisplayLength )
26+ "iPage" : oSettings . _iDisplayLength === - 1 ?
27+ 0 : Math . ceil ( oSettings . _iDisplayStart / oSettings . _iDisplayLength ) ,
28+ "iTotalPages" : oSettings . _iDisplayLength === - 1 ?
29+ 0 : Math . ceil ( oSettings . fnRecordsDisplay ( ) / oSettings . _iDisplayLength )
1730 } ;
18- }
31+ } ;
32+
1933
2034/* Bootstrap style pagination control */
2135$ . extend ( $ . fn . dataTableExt . oPagination , {
@@ -41,10 +55,10 @@ $.extend( $.fn.dataTableExt.oPagination, {
4155 } ,
4256
4357 "fnUpdate" : function ( oSettings , fnDraw ) {
44- var iListLength = jQuery . fn . dataTableExt . oPagination . iFullNumbersShowPages ;
58+ var iListLength = 5 ;
4559 var oPaging = oSettings . oInstance . fnPagingInfo ( ) ;
4660 var an = oSettings . aanFeatures . p ;
47- var i , j , sClass , iStart , iEnd , iHalf = Math . floor ( iListLength / 2 ) ;
61+ var i , ien , j , sClass , iStart , iEnd , iHalf = Math . floor ( iListLength / 2 ) ;
4862
4963 if ( oPaging . iTotalPages < iListLength ) {
5064 iStart = 1 ;
@@ -61,7 +75,7 @@ $.extend( $.fn.dataTableExt.oPagination, {
6175 iEnd = iStart + iListLength - 1 ;
6276 }
6377
64- for ( i = 0 , iLen = an . length ; i < iLen ; i ++ ) {
78+ for ( i = 0 , ien = an . length ; i < ien ; i ++ ) {
6579 // Remove the middle elements
6680 $ ( 'li:gt(0)' , an [ i ] ) . filter ( ':not(:last)' ) . remove ( ) ;
6781
@@ -93,3 +107,42 @@ $.extend( $.fn.dataTableExt.oPagination, {
93107 }
94108 }
95109} ) ;
110+
111+
112+ /*
113+ * TableTools Bootstrap compatibility
114+ * Required TableTools 2.1+
115+ */
116+ if ( $ . fn . DataTable . TableTools ) {
117+ // Set the classes that TableTools uses to something suitable for Bootstrap
118+ $ . extend ( true , $ . fn . DataTable . TableTools . classes , {
119+ "container" : "DTTT btn-group" ,
120+ "buttons" : {
121+ "normal" : "btn" ,
122+ "disabled" : "disabled"
123+ } ,
124+ "collection" : {
125+ "container" : "DTTT_dropdown dropdown-menu" ,
126+ "buttons" : {
127+ "normal" : "" ,
128+ "disabled" : "disabled"
129+ }
130+ } ,
131+ "print" : {
132+ "info" : "DTTT_print_info modal"
133+ } ,
134+ "select" : {
135+ "row" : "active"
136+ }
137+ } ) ;
138+
139+ // Have the collection use a bootstrap compatible dropdown
140+ $ . extend ( true , $ . fn . DataTable . TableTools . DEFAULTS . oTags , {
141+ "collection" : {
142+ "container" : "ul" ,
143+ "button" : "li" ,
144+ "liner" : "a"
145+ }
146+ } ) ;
147+ }
148+
0 commit comments