I am using the data table version 1.10.16. I am trying to make a pivot table. Depending on the option selected, it shows some columns or others. But when I choose an option and then choose other headers they don't work correctly.
Like in this example: https://codepen.io/cplaiuu/pen/oNNmeam
var columns, click = 0, table;
$('#show_table').on('click', function() {
if(table){
table.clear();
}
if(click == 0){
columns = [{'sTitle': 'Column 1'}, {'sTitle': 'Column 2'}, {'sTitle': 'Column 3'}, {'sTitle': 'Column '}];
}else{
columns = [{'sTitle': 'Column 1'}, {'sTitle': 'Column 2'}];
}
table = $('#example').DataTable({
dom: "<'row'<'col-sm-6'><'col-sm-6 button_columns' f>>" +
"<'row'<'col-sm-12'tr>>" +
"<'row'<'col-sm-5'><'col-sm-7'p>>",
responsive: true,
paging: false,
columns: columns,
language: {
zeroRecords: 'Empty',
infoEmpty: 'Empty',
search: "_INPUT_",
searchPlaceholder: 'Search',
},
destroy: true
//retrieve: true
});
click++;
});
If you click once it shows 4 columns but the second time you click, it would have to show only 2.
I try to destroy,clear() the datatable but without result.