I have a datatable with some settings,
$(tblCategory).dataTable({
"bPaging": true,
"sPaginationType": "full_numbers", //
"bPaginate": false, // shows both next prvious and show 10,20,30 entries
"sdom": 't',
"bprocessing": false, //
"sAjaxSource": "PM_MasterHelper.ashx?m=pmcfl&UserCode="+UserCode,
"bFilter": false, // search btn avail
"bDestroy": true
}
Now i would like to alter or add the settings like "bInfo":true, "bPaginate":true, when i click html input button.
Please help me to achieve this.
Try 1: I tried the following way but it doesn't affect the datatable.
oTable = $("tblCategory").dataTable();
var oSettings = oTable.fnSettings();
oSettings.bInfo= true;
oSettings.bPaginate = true;
You need to do a DataTable().destroy()
before apply the new options, example:
oTable = $("tblCategory").DataTable();
var oSettings = oTable.fnSettings();
oSettings.bInfo= true;
oSettings.bPaginate = true;
oTable.destroy();
$("tblCategory").DataTable(oSettings);
Also u need to use DataTable() with capital D.
You Should reinitialize the datatable:
//Default Options Object
var tableOptions = {
'bPaginate': true,
'searching' : true
};
//The table has already been initialized
var table = $("#ExampleTable");
tableOptions.bPaginate = true;
table.DataTable().destroy()
table.DataTable(tableOptions);
According to the documentation:
Simply put, DataTables does not allow initialisation options to be altered at any time other than at initialisation time. Any manipulation of the table after initialisation must be done through the API
The solution is to destroy the table:
table = $('#example').DataTable( {
paging: false
} );
table.destroy();
table = $('#example').DataTable( {
searching: false
} );
You can also do:
table = $('#example').DataTable( {
destroy: true,
searching: false
});
This has some performance consequences and it will also reset paging.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With