buttons.buttons.destroy
Function that is called when the button is destroyed.
Please note - this property requires the Buttons extension for DataTables.
Description
This function is provided to allow button authors to be able to assign custom events to the host DataTable or the button's DOM node, and then cleanly remove those events when a button is destroyed, ensuring that there are no memory leaks.
Of particular interest when using this method and the buttons.buttons.init
option to attach events, will be the buttons.buttons.namespace
option (accessible as the namespace
parameter of the third parameter passed into this function). The namespace
option is a unique namespacing string for every button, allowing events to be correctly removed without accidentally also removing other events.
Type
function destroy( dt, node, config )
- Description:
The function given here is called when the button is destroyed either by a call to
buttons().remove()
, when the Buttons instance is destroyed (buttons().destroy()
) or when the host DataTable is destroyed (destroy()
). It is provided to allow authors to removed events from the button preventing memory leaks.- Parameters:
Name Type Optional 1 dt
No A DataTables API instance for the host DataTable
2 node
No jQuery instance for the button node in question
3 config
No The button's configuration object
- Returns:
No return value is required or expected. No action is taken upon any value that is returned.
Default
- Value:
Default function depends upon the button type. Please refer to the button type documentation
Example
Button which has mouse enter / leave (hover) event listeners:
new DataTable('#myTable', {
layout: {
topEnd: {
buttons: [
{
text: '',
init: function (e, dt, node, config) {
node.on('mouseenter' + config.namespace, function () {
console.log('Mouse enter');
});
node.on('mouseleave' + config.namespace, function () {
console.log('Mouse leave');
});
},
destroy: function (dt, node, config) {
node.off('mouseenter' + config.namespace);
node.off('mouseleave' + config.namespace);
}
}
]
}
}
});