I have the following set up:
HighChart Graph
--------------------
DataTable Header
Month | Day | Total | etc
----------------------------------------
June | 2 | 10 | ...
June | 5 | 20 | ...
July | 29 | 10 | ...
Aug | 1 | 30 | ...
The series on my chart are titled as the months.
What I wanted to do is, when the legend is toggled it will hide the rows which MATCH the clicked series.
The question is, how do you integrate HighChart callbacks with DataTables’ filters?
In this answer, I assume that the variable
dataTableis equal to that of the DataTable object.First,
Lets set up the callback from HighCharts.
Secondly,
We are going to take this a step further and add detect when the series are toggled:
Thirdly,
We now know when the series were toggled. We can detect from which state they came from and which state they are going. We are not going to set up the filters for the DataTables.
Lastly,
We now have the
filterarray populated with the names of theseriesfrom the HighCharts Legend. We need to take this array, and apply it to a filter.Done!
The RegEx used above,
^((?!('+filter.join('|')+')).)*$will perform a negative look-ahead with an implode of thefilterarray with a|(pipe) character as the glue for anOR.