Usage

Initialisation and configuration of Select is performed through the select initialisation option for DataTables. This option can be given as a simple boolean value to enable Select with its default values, or as an object to provide more granular control.

Simple initialisation

In its most simple case, you can enable Select by simply setting select: true as an option in the DataTables initialisation:

new DataTable('#myTable', {
    select: true
});

If you do this, you may wish to use the select event to know when the end user has completed an action with Select, so any changes can be fed back to a database.

Options

For more complex cases, the select option can be used as an object allowing you to specify options such as selection style and which columns will active the selection action. In the following case, select.style is used to change the selection style to single - i.e. only one row can be selected at a time:

new DataTable('#myTable', {
    select: {
        style: 'single'
    }
});

Checkboxes

As you build more complex tables, you might find that you wish the selection action to be limited to just a single column at the start of the table. A checkbox column is often used for this, and Select makes it easy to do through by making a select rendering function available (i.e. a function that can be applied to columns.render).

The example below shows how this might be done - the first column is an empty once from the source data and has the DataTable.render.select() rendering method applied to columns.render. We also make use of select.selector to make sure that only the checkbox column will be used to trigger the selection action.

new DataTable('#example', {
    columnDefs: [
        {
            render: DataTable.render.select(),
            targets: 0
        }
    ],
    select: {
        selector: 'td:first-child'
    },
    order: [[1, 'asc']]
});

You can see this example in action here.

Reference

For a complete list of the options that Select supports, please refer to the DataTables initialisation options reference. The Select examples also demonstrate the options available.