1 /*! DataTables Bootstrap 3 integration
2 * ©2011-2015 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.
14 if ( typeof define === 'function' && define.amd ) {
16 define( ['jquery', 'datatables.net'], function ( $ ) {
17 return factory( $, window, document );
20 else if ( typeof exports === 'object' ) {
22 module.exports = function (root, $) {
27 if ( ! $ || ! $.fn.dataTable ) {
28 // Require DataTables, which attaches to jQuery, including
29 // jQuery if needed and have a $ property so we can access the
30 // jQuery object that is used
31 $ = require('datatables.net')(root, $).$;
34 return factory( $, root, root.document );
39 factory( jQuery, window, document );
41 }(function( $, window, document, undefined ) {
43 var DataTable = $.fn.dataTable;
46 /* Set the defaults for DataTables initialisation */
47 $.extend( true, DataTable.defaults, {
49 "<'row'<'col-sm-6'l><'col-sm-6'f>>" +
50 "<'row'<'col-sm-12'tr>>" +
51 "<'row'<'col-sm-5'i><'col-sm-7'p>>",
56 /* Default class modification */
57 $.extend( DataTable.ext.classes, {
58 sWrapper: "dataTables_wrapper form-inline dt-bootstrap",
59 sFilterInput: "form-control input-sm",
60 sLengthSelect: "form-control input-sm",
61 sProcessing: "dataTables_processing panel panel-default"
65 /* Bootstrap paging button renderer */
66 DataTable.ext.renderer.pageButton.bootstrap = function ( settings, host, idx, buttons, page, pages ) {
67 var api = new DataTable.Api( settings );
68 var classes = settings.oClasses;
69 var lang = settings.oLanguage.oPaginate;
70 var aria = settings.oLanguage.oAria.paginate || {};
71 var btnDisplay, btnClass, counter=0;
73 var attach = function( container, buttons ) {
74 var i, ien, node, button;
75 var clickHandler = function ( e ) {
77 if ( !$(e.currentTarget).hasClass('disabled') && api.page() != e.data.action ) {
78 api.page( e.data.action ).draw( 'page' );
82 for ( i=0, ien=buttons.length ; i<ien ; i++ ) {
85 if ( $.isArray( button ) ) {
86 attach( container, button );
94 btnDisplay = '…';
95 btnClass = 'disabled';
99 btnDisplay = lang.sFirst;
100 btnClass = button + (page > 0 ?
105 btnDisplay = lang.sPrevious;
106 btnClass = button + (page > 0 ?
111 btnDisplay = lang.sNext;
112 btnClass = button + (page < pages-1 ?
117 btnDisplay = lang.sLast;
118 btnClass = button + (page < pages-1 ?
123 btnDisplay = button + 1;
124 btnClass = page === button ?
131 'class': classes.sPageButton+' '+btnClass,
132 'id': idx === 0 && typeof button === 'string' ?
133 settings.sTableId +'_'+ button :
138 'aria-controls': settings.sTableId,
139 'aria-label': aria[ button ],
140 'data-dt-idx': counter,
141 'tabindex': settings.iTabIndex
145 .appendTo( container );
147 settings.oApi._fnBindAction(
148 node, {action: button}, clickHandler
157 // IE9 throws an 'unknown error' if document.activeElement is used
158 // inside an iframe or frame.
162 // Because this approach is destroying and recreating the paging
163 // elements, focus is lost on the select button which is bad for
164 // accessibility. So we want to restore focus once the draw has
166 activeEl = $(host).find(document.activeElement).data('dt-idx');
171 $(host).empty().html('<ul class="pagination"/>').children('ul'),
176 $(host).find( '[data-dt-idx='+activeEl+']' ).focus();