I like to create (if not exists) or update a DataTable. There are two cases with the update:
- The columns remain the same and only the rows are to be updated
- Columns and rows are to be updated (a different data basis) The distinction between creating and updating already works.
// get column names / keys from data array 'new_data' to 'columnNames'
// ...
if ($.fn.dataTable.isDataTable(table_id)) {
let datatable = $(table_id).DataTable();
datatable.clear();
datatable.rows.add(new_data);
datatable.draw('full-hold'); // keep current page
} else {
$(table_id).DataTable({
data: new_data,
columns: columns_array
});
}
How do I differentiate between updates with and without columns?
My idea was to check in the if-clause, weather the current table names equals the columnNames of the new data.
I tried datatable.columns().names() which is considered as no function.
The initial setup of the table is defined in HTML:
<table id="my_dataTable" class="table table-bordered display compact">
</table>````