Setting JavaScript using multiple tables
Setting JavaScript using multiple tables
![rimshot609](https://secure.gravatar.com/avatar/34b996a60bfd43813a276232616910fc/?default=https%3A%2F%2Fvanillicon.com%2F34b996a60bfd43813a276232616910fc_200.png&rating=g&size=120)
I have multiple tables with different ID's and I'm trying to get the Javascript file to apply the style for multiple ID's. Here is what I have that is not working:
$(function () {
$("[id*=tblAccount") || ("[id *= tblCustomer").prepend($("<thead></thead>").append($(this).find("tr:first"))).DataTable({
"paging": true,
"lengthChange": true,
"searching": true,
"ordering": true,
"info": true,
"autoWidth": false,
"dom": 'lBfrtip',
"buttons": ['excel', 'print', 'pdfHtml5']
});
})
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Hi @rimshot609 ,
It would probably make sense to do the
prepend
first, and then initialise all the tables afterwards. You can initialise them all with$('table').DataTable()
, or if there are multiple tables, assign a class to the table and initialise with$('table.init').DataTables()
.If that's no good, we're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.
Cheers,
Colin