| 4 |
lars |
1 |
/* Set the defaults for DataTables initialisation */
|
|
|
2 |
$.extend( true, $.fn.dataTable.defaults, {
|
|
|
3 |
"sDom": "<'row'<'span8'l><'span8'f>r>t<'row'<'span8'i><'span8'p>>",
|
|
|
4 |
"sPaginationType": "bootstrap",
|
|
|
5 |
"oLanguage": {
|
|
|
6 |
"sLengthMenu": "_MENU_ records per page"
|
|
|
7 |
}
|
|
|
8 |
} );
|
|
|
9 |
|
|
|
10 |
|
|
|
11 |
/* Default class modification */
|
|
|
12 |
$.extend( $.fn.dataTableExt.oStdClasses, {
|
|
|
13 |
"sSortAsc": "header headerSortDown",
|
|
|
14 |
"sSortDesc": "header headerSortUp",
|
|
|
15 |
"sSortable": "header"
|
|
|
16 |
} );
|
|
|
17 |
|
|
|
18 |
|
|
|
19 |
/* API method to get paging information */
|
|
|
20 |
$.fn.dataTableExt.oApi.fnPagingInfo = function ( oSettings )
|
|
|
21 |
{
|
|
|
22 |
return {
|
|
|
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 |
|
|
|
30 |
"iTotalPages": oSettings._iDisplayLength === -1 ?
|
|
|
31 |
|
|
|
32 |
};
|
|
|
33 |
};
|
|
|
34 |
|
|
|
35 |
|
|
|
36 |
/* Bootstrap style pagination control */
|
|
|
37 |
$.extend( $.fn.dataTableExt.oPagination, {
|
|
|
38 |
"bootstrap": {
|
|
|
39 |
"fnInit": function( oSettings, nPaging, fnDraw ) {
|
|
|
40 |
var oLang = oSettings.oLanguage.oPaginate;
|
|
|
41 |
var fnClickHandler = function ( e ) {
|
|
|
42 |
e.preventDefault();
|
|
|
43 |
if ( oSettings.oApi._fnPageChange(oSettings, e.data.action) ) {
|
|
|
44 |
fnDraw( oSettings );
|
|
|
45 |
}
|
|
|
46 |
};
|
|
|
47 |
|
|
|
48 |
$(nPaging).addClass('pagination').append(
|
|
|
49 |
'<ul>'+
|
|
|
50 |
'<li class="prev disabled"><a href="#">← '+oLang.sPrevious+'</a></li>'+
|
|
|
51 |
'<li class="next disabled"><a href="#">'+oLang.sNext+' → </a></li>'+
|
|
|
52 |
'</ul>'
|
|
|
53 |
);
|
|
|
54 |
var els = $('a', nPaging);
|
|
|
55 |
$(els[0]).bind( 'click.DT', { action: "previous" }, fnClickHandler );
|
|
|
56 |
$(els[1]).bind( 'click.DT', { action: "next" }, fnClickHandler );
|
|
|
57 |
},
|
|
|
58 |
|
|
|
59 |
"fnUpdate": function ( oSettings, fnDraw ) {
|
|
|
60 |
var iListLength = 5;
|
|
|
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);
|
|
|
64 |
|
|
|
65 |
if ( oPaging.iTotalPages < iListLength) {
|
|
|
66 |
iStart = 1;
|
|
|
67 |
iEnd = oPaging.iTotalPages;
|
|
|
68 |
}
|
|
|
69 |
else if ( oPaging.iPage <= iHalf ) {
|
|
|
70 |
iStart = 1;
|
|
|
71 |
iEnd = iListLength;
|
|
|
72 |
} else if ( oPaging.iPage >= (oPaging.iTotalPages-iHalf) ) {
|
|
|
73 |
iStart = oPaging.iTotalPages - iListLength + 1;
|
|
|
74 |
iEnd = oPaging.iTotalPages;
|
|
|
75 |
} else {
|
|
|
76 |
iStart = oPaging.iPage - iHalf + 1;
|
|
|
77 |
iEnd = iStart + iListLength - 1;
|
|
|
78 |
}
|
|
|
79 |
|
|
|
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();
|
|
|
83 |
|
|
|
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) {
|
|
|
90 |
e.preventDefault();
|
|
|
91 |
oSettings._iDisplayStart = (parseInt($('a', this).text(),10)-1) * oPaging.iLength;
|
|
|
92 |
fnDraw( oSettings );
|
|
|
93 |
} );
|
|
|
94 |
}
|
|
|
95 |
|
|
|
96 |
// Add / remove disabled classes from the static elements
|
|
|
97 |
if ( oPaging.iPage === 0 ) {
|
|
|
98 |
$('li:first', an[i]).addClass('disabled');
|
|
|
99 |
} else {
|
|
|
100 |
$('li:first', an[i]).removeClass('disabled');
|
|
|
101 |
}
|
|
|
102 |
|
|
|
103 |
if ( oPaging.iPage === oPaging.iTotalPages-1 || oPaging.iTotalPages === 0 ) {
|
|
|
104 |
$('li:last', an[i]).addClass('disabled');
|
|
|
105 |
} else {
|
|
|
106 |
$('li:last', an[i]).removeClass('disabled');
|
|
|
107 |
}
|
|
|
108 |
}
|
|
|
109 |
}
|
|
|
110 |
}
|
|
|
111 |
} );
|
|
|
112 |
|
|
|
113 |
|
|
|
114 |
/*
|
|
|
115 |
* TableTools Bootstrap compatibility
|
|
|
116 |
* Required TableTools 2.1+
|
|
|
117 |
*/
|
|
|
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",
|
|
|
122 |
"buttons": {
|
|
|
123 |
"normal": "btn",
|
|
|
124 |
"disabled": "disabled"
|
|
|
125 |
},
|
|
|
126 |
"collection": {
|
|
|
127 |
"container": "DTTT_dropdown dropdown-menu",
|
|
|
128 |
"buttons": {
|
|
|
129 |
"normal": "",
|
|
|
130 |
"disabled": "disabled"
|
|
|
131 |
}
|
|
|
132 |
},
|
|
|
133 |
"print": {
|
|
|
134 |
"info": "DTTT_print_info modal"
|
|
|
135 |
},
|
|
|
136 |
"select": {
|
|
|
137 |
"row": "active"
|
|
|
138 |
}
|
|
|
139 |
} );
|
|
|
140 |
|
|
|
141 |
// Have the collection use a bootstrap compatible dropdown
|
|
|
142 |
$.extend( true, $.fn.DataTable.TableTools.DEFAULTS.oTags, {
|
|
|
143 |
"collection": {
|
|
|
144 |
"container": "ul",
|
|
|
145 |
"button": "li",
|
|
|
146 |
"liner": "a"
|
|
|
147 |
}
|
|
|
148 |
} );
|
|
|
149 |
}
|
|
|
150 |
|