What if the User wants to Refresh the Data or it has Different Search Criteria?
For our case, we had the tables separated by year. This meant that the table could have different columns based on the year that the user had selected. Thankfully, Datatables has built-in methods that allow you to remove all Datatables related items from your table.
So if you are wanting to refresh the table, simply call the destroy() method on your Datatable, remove all the headers and rows so that the table is just the scaffolding again, and then call all the functions that I just outlined above.
We had some trouble figuring out the solution to dealing with dynamically created Datatables, but we hope this blog will ease some of your pain if you find yourself in the same situation.