Skip to content

Commit 5e7d5d7

Browse files
committed
New: Support for DataTables 2's layout option. More details on that as work continues on DataTables 2
1 parent 0967eb8 commit 5e7d5d7

File tree

1 file changed

+29
-9
lines changed

1 file changed

+29
-9
lines changed

js/dataTables.buttons.js

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@ var _dtButtons = DataTable.ext.buttons;
4848
*/
4949
var Buttons = function( dt, config )
5050
{
51+
// If not created with a `new` keyword then we return a wrapper function that
52+
// will take the settings object for a DT. This allows easy use of new instances
53+
// with the `layout` option - e.g. `topLeft: $.fn.dataTable.Buttons( ... )`.
54+
if ( !(this instanceof Buttons) ) {
55+
return function (settings) {
56+
return new Buttons( settings, dt ).container();
57+
};
58+
}
59+
5160
// If there is no config set it to an empty object
5261
if ( typeof( config ) === 'undefined' ) {
5362
config = {};
@@ -248,12 +257,16 @@ $.extend( Buttons.prototype, {
248257
},
249258

250259
/**
251-
* Get a button's node
252-
* @param {node} node Button node
253-
* @return {jQuery} Button element
260+
* Get a button's node of the buttons container if no button is given
261+
* @param {node} [node] Button node
262+
* @return {jQuery} Button element, or container
254263
*/
255264
node: function ( node )
256265
{
266+
if ( ! node ) {
267+
return this.dom.container;
268+
}
269+
257270
var button = this._nodeToButton( node );
258271
return $(button.node);
259272
},
@@ -1902,17 +1915,24 @@ $(document).on( 'init.dt plugin-init.dt', function (e, settings) {
19021915
}
19031916
} );
19041917

1918+
function _init ( settings ) {
1919+
var api = new DataTable.Api( settings );
1920+
var opts = api.init().buttons || DataTable.defaults.buttons;
1921+
1922+
return new Buttons( api, opts ).container();
1923+
}
1924+
19051925
// DataTables `dom` feature option
19061926
DataTable.ext.feature.push( {
1907-
fnInit: function( settings ) {
1908-
var api = new DataTable.Api( settings );
1909-
var opts = api.init().buttons || DataTable.defaults.buttons;
1910-
1911-
return new Buttons( api, opts ).container();
1912-
},
1927+
fnInit: _init,
19131928
cFeature: "B"
19141929
} );
19151930

1931+
// DataTables 2 layout feature
1932+
if ( DataTable.ext.features ) {
1933+
DataTable.ext.features.register( 'buttons', _init );
1934+
}
1935+
19161936

19171937
return Buttons;
19181938
}));

0 commit comments

Comments
 (0)