Setting $.fn.dataTable.defaults not working
Setting $.fn.dataTable.defaults not working

Hi. I'm pulling my hair with an issue I found I can not resolve:
I have a table which is created using a given Web Component I can NOT modify **in any way (as it's part of my company's library of components).
The thing is the component Initializes a new Table with some parameters, BUT I want to add/extend with some new keys to the configuration options. I wrote the following code in order to push columnsDef without any success:
First HTML loads the plugin:
<script src="datatables.min"></script>
Then HTML has following logic:
<script>
$.extend($.fn.dataTable.defaults, {
"columnDefs": [ {
"targets": [1],
"visible": false
} ]
} );
</script>
Then, the library component loads with the following code (typescript):
const options = this.getDatatableOptions();
this.api = this.$(tableElement).DataTable(options);
getDatatableOptions() {
const options: any = {
dom: "Bt",
buttons: ["copy", "excel", "print"],
pageLength: parseInt(this.itemsPage, 10),
paging: this.pagination
};
And Finally my table loads data:
tablaJS = document.querySelector("#listingTable");
tablaJS.ajax.url("http://localhost:8081/src/js/MOCK_DATA.json").load();
From the code above I was expecting to see column 1 turn invisible according to columnDefs
Anything what I'm doing wrong?
Answers
I'm not sure what's going wrong there I'm afraid. It appears to work okay here.
Could you link to a page showing the issue please?
Allan
Hi Allan. Unfortunately I don't have a public url.
I can add my complete javascript file (the one that reads the data). Maybe it has to do with the way I'm loading these data?.
This javascript is last one loaded in the HTML page:
JSON Mock:
If I add a console.log Before and After the Script where my mm-listing component creates the table I can see the columnDef correctly. However the table doesn't seem to refresh these values
Are you able to modify this example to match the behaviour you are seeing?
Thanks,
Allan