Mulitple tables

Mulitple tables

aelghaelgh Posts: 6Questions: 4Answers: 0

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

1
2
3
4
5
6

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

  • kthorngrenkthorngren Posts: 20,307Questions: 26Answers: 4,769

    The init options need to be within the Datatables initialization parameters, ie this:

    $('.display').DataTable({
     
    })
    

    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

This discussion has been closed.