1 /*! DataTables Bootstrap 3 integration
2 * ©2011-2014 SpryMedia Ltd - datatables.net/license
6 * DataTables integration for Bootstrap 3. This requires Bootstrap 3 and
7 * DataTables 1.10 or newer.
9 * This file sets the defaults and adds options to DataTables to style its
10 * controls using Bootstrap. See http://datatables.net/manual/styling/bootstrap
11 * for further information.
13 (function(window, document, undefined){
15 var factory = function( $, DataTable ) {
19 /* Set the defaults for DataTables initialisation */
20 $.extend( true, DataTable.defaults, {
22 "<'row'<'col-sm-6'l><'col-sm-6'f>>" +
23 "<'row'<'col-sm-12'tr>>" +
24 "<'row'<'col-sm-5'i><'col-sm-7'p>>",
29 /* Default class modification */
30 $.extend( DataTable.ext.classes, {
31 sWrapper: "dataTables_wrapper form-inline dt-bootstrap",
32 sFilterInput: "form-control input-sm",
33 sLengthSelect: "form-control input-sm"
37 /* Bootstrap paging button renderer */
38 DataTable.ext.renderer.pageButton.bootstrap = function ( settings, host, idx, buttons, page, pages ) {
39 var api = new DataTable.Api( settings );
40 var classes = settings.oClasses;
41 var lang = settings.oLanguage.oPaginate;
42 var btnDisplay, btnClass, counter=0;
44 var attach = function( container, buttons ) {
45 var i, ien, node, button;
46 var clickHandler = function ( e ) {
48 if ( !$(e.currentTarget).hasClass('disabled') ) {
49 api.page( e.data.action ).draw( false );
53 for ( i=0, ien=buttons.length ; i<ien ; i++ ) {
56 if ( $.isArray( button ) ) {
57 attach( container, button );
65 btnDisplay = '…';
66 btnClass = 'disabled';
70 btnDisplay = lang.sFirst;
71 btnClass = button + (page > 0 ?
76 btnDisplay = lang.sPrevious;
77 btnClass = button + (page > 0 ?
82 btnDisplay = lang.sNext;
83 btnClass = button + (page < pages-1 ?
88 btnDisplay = lang.sLast;
89 btnClass = button + (page < pages-1 ?
94 btnDisplay = button + 1;
95 btnClass = page === button ?
102 'class': classes.sPageButton+' '+btnClass,
103 'id': idx === 0 && typeof button === 'string' ?
104 settings.sTableId +'_'+ button :
109 'aria-controls': settings.sTableId,
110 'data-dt-idx': counter,
111 'tabindex': settings.iTabIndex
115 .appendTo( container );
117 settings.oApi._fnBindAction(
118 node, {action: button}, clickHandler
127 // IE9 throws an 'unknown error' if document.activeElement is used
128 // inside an iframe or frame.
132 // Because this approach is destroying and recreating the paging
133 // elements, focus is lost on the select button which is bad for
134 // accessibility. So we want to restore focus once the draw has
136 activeEl = $(document.activeElement).data('dt-idx');
141 $(host).empty().html('<ul class="pagination"/>').children('ul'),
146 $(host).find( '[data-dt-idx='+activeEl+']' ).focus();
152 * TableTools Bootstrap compatibility
153 * Required TableTools 2.1+
155 if ( DataTable.TableTools ) {
156 // Set the classes that TableTools uses to something suitable for Bootstrap
157 $.extend( true, DataTable.TableTools.classes, {
158 "container": "DTTT btn-group",
160 "normal": "btn btn-default",
161 "disabled": "disabled"
164 "container": "DTTT_dropdown dropdown-menu",
167 "disabled": "disabled"
171 "info": "DTTT_print_info"
178 // Have the collection use a bootstrap compatible drop down
179 $.extend( true, DataTable.TableTools.DEFAULTS.oTags, {
191 // Define as an AMD module if possible
192 if ( typeof define === 'function' && define.amd ) {
193 define( ['jquery', 'datatables'], factory );
195 else if ( typeof exports === 'object' ) {
197 factory( require('jquery'), require('datatables') );
200 // Otherwise simply initialise as normal, stopping multiple evaluation
201 factory( jQuery, jQuery.fn.dataTable );
205 })(window, document);