Feature plug-in development
DataTables places a number of control and information elements around a table. We term these components "features". DataTables has a number of features build in which are registered via an API that is publicly available to register additional features as plug-ins. This page discusses how to use the feature API.
Features for DataTables are used through the layout
option which provides the ability for a developer to position the feature around the table as they require.
Features are registered with the DataTable.feature.register()
static API method. Please see the documentation for that method for full details of the parameters that are passed into it.
Feature example
The code before shows how a feature called myToolbar
might be created and registered for use with DataTables. It creates a div
element which can contain any HTML required (and suitable listeners on those elements), this is then returned to DataTables to display around the table:
1234567891011121314DataTable.feature.register(
'myToolbar'
,
function
(settings, opts) {
// Define defaults
let
options = Object.assign({
option1:
false
,
option2:
false
}, opts);
let
container = document.createElement(
'div'
);
// do something with the options and container
// ...
return
container;
});
Feature usage
Once a feature has been registered you can reference it in the layout
object for table control layout:
12345678910new
DataTable(
'#myTable'
, {
layout: {
topStart: {
myToolbar: {
option1:
true
,
option2:
false
}
}
}
});
Publish your plug-ins
If you create a feature plug-in for DataTables, please let us know! Others may benefit from your plug-in and I (and the community as a whole) will be very grateful for your contribution.
Post new comment
Contributions in the form of tips, code snippets and suggestions for the above material are very welcome. To post a comment, please use the form below. Text is formatted by Markdown.
To post comments, please sign in to your DataTables account, or register:
Any questions posted here will be deleted without being published.
Please post questions in the Forums. Comments are moderated.