Is it possible to change any DataTables settings once the table has been initialised, if so how?
Is it possible to change any DataTables settings once the table has been initialised, if so how?
I'm relatively new to DataTables and I've been doing some investigating to the issue above. So far I've found that in the newer versions of DataTables, it is impossible to change any settings after the table has been drawn. Not only that, but it is also advised against if you are not strong with DataTables(which I am not).
Basically, I am using the DataTables 'select' extension with the basic initialisation (able to multiselect while holding down shft etc). Now the issue occurs because there is a setting in my application which I would like to be able to check and depending on the value, continue as normal or only allow the user to select one row at a time. I could do this before I initialise the table but that is the least preferred option as there would be a lot of repeated code for the sake of one line. So my question still remains, is it possible to change any settings after the table has been initialised and if so, how?
If it's possible, please post an example below. Thanks
Answers
Hi, I think I have found an answer, but this only works if you want to change the settings BEFORE initalising the datatable. I think I phrased my question wrong. Basically, you can actually set the default setting values for multiple datatables using the
fn.dataTable.defaults
function. Therefore I check the value before I initialise the data table and then either set theselect
option to true or false. Simple really, just took some digging. Saved me around 150 extra lines :)Eg:
if(2 == 1){
$.extend(true, $.fn.dataTable.defaults, {
select: true
});
}
else{
$.extend(true, $.fn.dataTable.defaults, {
select: false
});
}