Getting the Initialisation Parameters for DataTables

I saw that there was a similar question to which I was working in Stack Overflow, Getting the initialisation object from DataTables, I planned to expand this to suit the questions' needs as I am linking it to the question as well.

This is the follow up for the Conditional Formatting in JavaScript like Excel and other spreadsheet solutions as I made a blunder previously. The requirement was a DataTable needs to be killed and reinitialised for updating the HTML Table with some manual methods. So I had to find the initialisation object. Unfortunately, the ideas given in the DataTables forums were like:

  1. Create an initialisation object and store globally.
  2. Initialise the DataTables with the global object.
  3. Kill the DataTables using the destroy() method.
  4. Initialise with the same initialisation object defined in the first method.

This solution is totally absurd considering the way, the DataTables are initialised and rendered in my application. My proposed solution to my manager was something different. Why not apply the transformation before the DataTables are initialised?

But unfortunately, corporate guidelines do not allow the core code to be changed by the newbies!

The reply was kind of baffling but I have to accept as these are the worst scenarios for developers working in a corporate environment, where the code is managed by literally hundreds of team members! So, I thought of using my other method.

From the manual of DataTable().init(), it does have an option. The following function gives us an approximate initialisation object:

$("#example").DataTable().init();

Although, this will not give you the exact initialisation object that we have used it when we initialised it, at least we can get to make the same DataTable configuration as how it was before it was killed. A CodePen to demonstrate the same is as follows:

See the Pen DataTable Get Init Object by Praveen Kumar (@praveenscience) on CodePen.

I hope this helps someone. As usual, if you have a better solution or any suggestions, please do pen down in the comments. Thanks.



comments powered by Disqus