{hero}

DataTable.feature.register()

Since: DataTables 2.0

Create a new feature that can be used for layout.

Description

DataTables makes use of a "feature" registration system to define components which can be displayed around a table and are typically used to control the table in some fashion. The built in table controls such as pageLength and paging use this system, as do extensions such as Buttons. You can also use it to create your own feature plug-ins for DataTables that will be used with its layout option.

Defining your own feature plug-in is good for code reuse (i.e. you want to use the feature on more than one table) and also for sharing with the community. If you would like to share a plug-in post about it in the forum!

This function is used to register your own feature plug-in, giving it the name that will be used to reference it in layout and the function that will define its container element and behaviour.

Options for a feature plug-in can be defined, but there should be sensible details since options are not required when using layout. For example the following two are valid to make use of a feature called myToolbar:

new DataTable('#myTable', {
    layout: {
        topStart: 'myToolbar'
    }
});
new DataTable('#myTable', {
    layout: {
        topStart: {
            myToolbar: {
                option1: true,
                option2: false
            }
        }
    }
});

The parameters defined are passed into the constructor for the plug-in as the second parameter (which will be null if no value is given, such as in the first code block above). So for the above, the following feature registration might be used:

DataTable.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;
});

Type

function register( name, construct )

Description:
Returns:

No value is returned.