Multiple DataTables in one page?
Multiple DataTables in one page?
Mert1296
Posts: 43Questions: 7Answers: 0
Hey everybody,
I need multiple DataTables on my Website with different numbers of columns. I have 3 tables with 3 different IDs and I'm also coding 3 different variables for each table but there's only one table which is a DataTable.
Here is an example:
var table = $('#table1').DataTable({
paging: false,
select: {
style: 'single'
},
columnDefs: [
{
targets:[0,1,2,3,4,5],
orderable: false,
searchable: false
}
]
});
var table2 = $('#table2').DataTable({
paging: false,
select: {
style: 'single'
},
columnDefs: [
{
targets:[0,1,2,3],
orderable: false,
searchable: false
}
]
});
just #table1 is a DataTable..
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Your code works in this test case:
http://live.datatables.net/zumaqoye/1/edit
The issue is somewhere else in your page. Look at the browser's console for errors.
Make sure your HTML is correct for the other tables. Maybe you can update the test case to replicate your issue.
Kevin
So I put the two tables in the testcase and the second table isn't a DataTable:
http://live.datatables.net/lawezosa/1/edit
Just ignore the PHP-Code in my tables
Your
columnDefs.targets
is causing this error (seen in the browser's console):Uncaught TypeError: Cannot set property '_DT_CellIndex' of undefined
This is causing the Javascript to stop thus not initializing the second table.
The first table has 2 columns but your targets range is
[0,1,2,3,4,5]
. Also the same problem with your second table. See the updated working example:http://live.datatables.net/vuzeximu/1/edit
Kevin
Sorry for the late answer, didn't see that you wrote. Yes it worked! Thank you very much!
But I have another issue.. I have 6 Tables on my website but I can only use 5 as a DataTable. As soon I code the 6th table to a DataTable, the 6th one isn't a DT..
There is not a built in limit. The problem is specific to your page. I would start by looking for errors in your browser's console.
Kevin