question about table.display
question about table.display
I need to understand this structure:
$(document).ready(function() {
$('table.display').DataTable();
} );
I get the $(document).ready... part. What I am attempting t do is to write two Datatables to a div on my page. The examples (eg: https://datatables.net/examples/basic_init/multiple_tables.html) show the creation of the tables using HTML code, not using Datatable syntax.
I don't understand several things about the $('table.display').DataTable() command:
1) How are the tables to be displayed identified? I have my two tables identified as instances of a "class = 'display'", but Datatables cannot find them or render them.
2) Can I construct the tables using Datatables code, not HTML? Can I write the Datatables to variables and then reference the variables in the display command?
3) What options do I have to display two tables in a div? Ideally, these two tables would be linked so that a sort command will reorder both tables. Also, I want to wrap these tables in a set of download buttons. I'd appreciate any examples.
TIA
This question has an accepted answers - jump to answer
Answers
Colin
Still having problems displaying multiple tables.
I am writing to two separate tables within a single div on my page. I have two data arrays, one containing population counts ("tab_data_Pop") and the other containing growth rates to be presented as percentages ("tad_data_Gr").
I am writing the table element for each table like this:
The DataTable code is the same for each table with 2 exceptions: the render.number function and the data command:
The first table displays. The second table doesn't. The second table throws the following error message:
I don't understand why the second table won't render, and I don't understand the source of the error.
Sorry for the long post.
TIA
Could you update the example in my last comment above to demonstrate your issue, please - it'll help us to debug the problem,
Colin
I didn't see a comment fro December 28
My problem is shown in the longish post, posted at 1:28 am on December 28.
I have been experimenting with writing the two tables. When I generate a single table, either to "#growthtab1" or to "#growthtab2", the selected table renders. This works regardless of the table being generated.
When I try to generate both tables I receive the error "datatables.min.js:113 Uncaught (in promise) TypeError: h.sTitle.replace is not a function..."
None of this makes any sense to me.
I copied your code into this test case:
http://live.datatables.net/tegikane/1/edit
It loads both tables with made up table data and labels. I commented out the
word
button as there is no builtin word button type. See the Builtin buttons docs for a listing of builtin buttons.Please update the test case or post a link to your page to show the issue you are having.
You can set default Datatable settings to apply to all Datatables on the page. See the options docs for more details.
Kevin
Thanks. I was able to make this work by appending the HTML code for the table to "#growthtab1" and "#growthtab2" and then applying the DataTable specifications to each table element in turn.
BTW, I had to create a Word button and the functions download a table in MS Word. My users insist on downloading everything in multiple formats.
Cheers
Sounds like you have everything working the way you want, correct?
Kevin