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",
6 "sLengthMenu": "_MENU_ records per page"
11 /* Default class modification */
12 $.extend( $.fn.dataTableExt.oStdClasses, {
13 "sWrapper": "dataTables_wrapper form-inline"
17 /* API method to get paging information */
18 $.fn.dataTableExt.oApi.fnPagingInfo = function ( oSettings )
21 "iStart": oSettings._iDisplayStart,
22 "iEnd": oSettings.fnDisplayEnd(),
23 "iLength": oSettings._iDisplayLength,
24 "iTotal": oSettings.fnRecordsTotal(),
25 "iFilteredTotal": oSettings.fnRecordsDisplay(),
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 )
34 /* Bootstrap style pagination control */
35 $.extend( $.fn.dataTableExt.oPagination, {
37 "fnInit": function( oSettings, nPaging, fnDraw ) {
38 var oLang = oSettings.oLanguage.oPaginate;
39 var fnClickHandler = function ( e ) {
41 if ( oSettings.oApi._fnPageChange(oSettings, e.data.action) ) {
46 $(nPaging).addClass('pagination').append(
48 '<li class="prev disabled"><a href="#">← '+oLang.sPrevious+'</a></li>'+
49 '<li class="next disabled"><a href="#">'+oLang.sNext+' → </a></li>'+
52 var els = $('a', nPaging);
53 $(els[0]).bind( 'click.DT', { action: "previous" }, fnClickHandler );
54 $(els[1]).bind( 'click.DT', { action: "next" }, fnClickHandler );
57 "fnUpdate": function ( oSettings, fnDraw ) {
59 var oPaging = oSettings.oInstance.fnPagingInfo();
60 var an = oSettings.aanFeatures.p;
61 var i, ien, j, sClass, iStart, iEnd, iHalf=Math.floor(iListLength/2);
63 if ( oPaging.iTotalPages < iListLength) {
65 iEnd = oPaging.iTotalPages;
67 else if ( oPaging.iPage <= iHalf ) {
70 } else if ( oPaging.iPage >= (oPaging.iTotalPages-iHalf) ) {
71 iStart = oPaging.iTotalPages - iListLength + 1;
72 iEnd = oPaging.iTotalPages;
74 iStart = oPaging.iPage - iHalf + 1;
75 iEnd = iStart + iListLength - 1;
78 for ( i=0, ien=an.length ; i<ien ; i++ ) {
79 // Remove the middle elements
80 $('li:gt(0)', an[i]).filter(':not(:last)').remove();
82 // Add the new list items and their event handlers
83 for ( j=iStart ; j<=iEnd ; j++ ) {
84 sClass = (j==oPaging.iPage+1) ? 'class="active"' : '';
85 $('<li '+sClass+'><a href="#">'+j+'</a></li>')
86 .insertBefore( $('li:last', an[i])[0] )
87 .bind('click', function (e) {
89 oSettings._iDisplayStart = (parseInt($('a', this).text(),10)-1) * oPaging.iLength;
94 // Add / remove disabled classes from the static elements
95 if ( oPaging.iPage === 0 ) {
96 $('li:first', an[i]).addClass('disabled');
98 $('li:first', an[i]).removeClass('disabled');
101 if ( oPaging.iPage === oPaging.iTotalPages-1 || oPaging.iTotalPages === 0 ) {
102 $('li:last', an[i]).addClass('disabled');
104 $('li:last', an[i]).removeClass('disabled');
113 * TableTools Bootstrap compatibility
114 * Required TableTools 2.1+
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",
122 "disabled": "disabled"
125 "container": "DTTT_dropdown dropdown-menu",
128 "disabled": "disabled"
132 "info": "DTTT_print_info modal"
139 // Have the collection use a bootstrap compatible dropdown
140 $.extend( true, $.fn.DataTable.TableTools.DEFAULTS.oTags, {