Datatables initialization error and another question
Datatables initialization error and another question
I am using datatables along with highcharts. My goal is when user clicks on buttons 2023, 2022 and ABC button, the charts should reload so that gives animation effect to the user. When I do this, I am running into following issues:
1) I get datatables initialization error when I click on any of the buttons
2) ABC button has chart type column, but it converts it into pie chart.
Here is my test case: https://codepen.io/Shawnny-Tandon/pen/bGJeOev
Thanks.
This question has an accepted answers - jump to answer
Answers
When clicking one of the buttons you are getting this error:
Followed by this error:
Looks like the problem is here:
The first error is caused by this:
I think you want to use
tableId
instead, like this:That should eliminate both errors.
You have this click event handler for all three buttons:
It calls
reloadChart()
which reinitializes Datatables and the chart. It is hard coded to create a pie chart. You will need to change your code logic to handle the tyoe of chart. Maybe pass the chart type into the function? Or possibly use a different click event handler for the ABC button. Many options of what you can do. This is not a Datatables specific issue.Kevin
Thankyou. I fixed the column chart displaying pie chart issue. However if I change the
code to $('#' + tableId).DataTable().destroy();, clicking on buttons do not animate reloading. The whole reason I am destroying and reloading chart is to animate the charts again when user clicks on the buttons. Is there a way around it? Thanks.
https://codepen.io/Shawnny-Tandon/pen/bGJeOev
Sounds like you want to use jQuery empty() for the
div
to remove the chart. You will want todestroy
the Datatable before using jQuery empty() on thediv
that it is in.Kevin
That did it, thanks!