How to reinitialize a jQuery datatable? I even tried to remove table element. Still that table is displaying. My code is like this:
function removeExistingDat
You can reinitialize the datatable by clearing it and then adding the element using fnAddData()
.
First check whether the dataTable
exists or not. The function fnClearTable()
will clear the data from table.
In the code, dataTable
is datatable variable and results
is the id
of table.
if(typeof dataTable === 'undefined'){
dataTable = $('#results').dataTable({
"aLengthMenu": [
[25, 50, 100, 200],
[25, 50, 100, 200]
],
"iDisplayLength" : 25,
"sPaginationType": "full_numbers",
});
}else dataTable.fnClearTable();
Then again add the data using fnAddData.
dataTable.fnAddData( [key, assignee, summary, status, days]);