Setting JavaScript using multiple tables

Setting JavaScript using multiple tables

rimshot609rimshot609 Posts: 9Questions: 6Answers: 0

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

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599
    Answer ✓

    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

This discussion has been closed.