Multiple Table Setups

Multiple Table Setups

DalderDalder Posts: 30Questions: 12Answers: 1

Hello,

I've been reading through the manual about multiple DataTables on a single page.

I'm using the single declaration method.

var tables = $('.table').DataTable( {
searching: false,
ordering: false,
paging: false, bInfo : false,
select: {
    style: 'multi'
}} );

Whilst this works in the fact that both tables on my page are turned into DataTables, it would appear that only the 2nd DataTables is accessible via the tables variable.

I've read through as much information on multiple DataTables as I can find but still can't seem to access both tables from the single variable.

Short of instantiating both tables independently, how can I access both tables?

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,142Questions: 1Answers: 2,586

    Hi @Dalder ,

    This example here should help.

    You can access it with table(), i.e. tables.table(0) and tables.table(1).

    Cheers,

    Colin

  • DalderDalder Posts: 30Questions: 12Answers: 1

    Hi Colin,

    Thanks for the example and the response.

    I tried your solution with my setup and unfortunately it still doesn't work.

    I've created an example here where it still doesn't work, so I imagine I'm doing something wrong!

    Any further help you can offer is greatly appreciated.

    Thanks,

    Dan

  • colincolin Posts: 15,142Questions: 1Answers: 2,586
    Answer ✓

    Hi Dan,

    Yep, something wrong :) You had the ID the same for both tables, which isn't valid HTML and therefore breaks stuff. If you make them unique, as in here, everything works a treat.

    Cheers,

    Colin

  • DalderDalder Posts: 30Questions: 12Answers: 1

    D'oh!

    At one point in time they definitely had separate IDs, must have got a a bit over zealous with the copy and pasting.

    Oh well, thanks for pointing out my stupid mistake, all is working as intended.

    Dan

This discussion has been closed.