0
votes

I am using angular 4 with data table ... Right side scroll bar is not working. When I add this the in my data table I am getting this error. how can I solve this? this is my code $(document).ready(function() { $('#example').DataTable( { "scrollX": true } ); } );

<table id="example" class="display nowrap" cellspacing="0" width="100%">

I am getting a message in an alert on my browser "DataTables warning: table id=example - Cannot reinitialise DataTable. For more information"

I am using this data table enter link description here

3
you are using angularjs then why you initialize scrollx using a jquery ? - Ketan Modi

3 Answers

1
votes

try like this:

ngOnInit(): void {
    this.dtOptions = {
      scrollX: true
    };
}
0
votes

This issue arises if there is a previous initialization of DataTable. So, either set the bDestroy property of the DataTable to true like the following,

$('#dataTable').dataTable({
    .
    .        
    "bDestroy": true
});

OR remove the previously initialised DataTable such as initializing in the begining of the onload/ready method like the following,

$(document).ready(function() {
    $('.dataTable').dataTable();
} );
0
votes

Try this.

this.dtOptions = {
      ...
      destroy: true,
      ...
    };