selected
Button that is enabled when one or more items are selected in the table.
Please note - this property requires the Select extension for DataTables.
Description
When working with item selection in a DataTable you will typically wish to provide your end users with the ability to take some kind of action when items are selected. This button provides a basic framework for that, as it is dynamically enabled and disabled automatically as items in the table are selected.
By providing an action
function (buttons.buttons.action
/ button().action()
) this button can be used to perform whatever operation is required on the table and its selected items.
Example
DataTables initialisation: Count the number of selected rows:
new DataTable('#myTable', {
buttons: [
{
extend: 'selected',
text: 'Count selected rows',
action: function (e, dt, button, config) {
alert(
dt.rows({ selected: true }).indexes().length + ' row(s) selected'
);
}
}
]
});