Mulitple tables
Mulitple tables
Hello,
On my page I have 6 tables all with editor option. All these table receive its data from the same SP but the values in each table differs. After reading on the forum I saw that you need 1 instance for each editor table and since my tables contain different values I decided to create six instances of them as well. So I have
And I have six different JS files one for each table. I feel tho like this is really bad. First I created it as one table instance and took the class of all the tables like
$('.display').DataTable({
})
but with this method I had a hard time spliting the data from the ajax call to differ between table 1-6.
So my question is: If you have multiple tables that contain different values from the same datasource AND all shall be editable and be able to submit data to the db, is this the right way to do it?
I am asking this because it feels like I have to duplicate a lot of code which is obv bad. I just have a gut feeling that I am doing it in the wrong way.
Also, if this is the way to do it, is it possible to set stuff as paging,searching,processing,columns etc on class level?
Like I create a SixTableConfigFile.js and in it I can access all my table with class name and set default rules that are anyway same for all my tables.
$(.display).on('init.dt', function(){ //or something similar
paging : true,
searching : false,
processing : false
columns : myColumns
});
Br,
Anton
Answers
The init options need to be within the Datatables initialization parameters, ie this:
You can place all the parameters that are the same within that block of code. You can also use HTML5 Atrributes of options that are different for each table, like maybe
ajax
.You can also set Option Defaults.
Kevin