Skip to content
Advertisement

Multiple Tables on Datatables with different option

I have multiple table (tbUser, tbRole, tbJob) and i want to make my code simple.

this is what i done before:

JavaScript

Each tables has different options, columns and have one thing in common has column [action] to put View/Edit/Remove button. Is there a simple way to do jquery event click action button in each table.

This is my code:

JavaScript

and I’ve tried :

JavaScript

Advertisement

Answer

Firstly your edit button needs to be targetted using a class not an ID, otherwise it will only ever find the first button.

Create an object that holds a reference to each of your tables. I’m using the table id as the key, and the instantiated datatable as the value.

JavaScript

Then with your button click, identify which table it is part of and use that to grab the table instantiation from the object you created earlier

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement