Possible to Initialise without the table having an ID?

Possible to Initialise without the table having an ID?

sm9sm9 Posts: 27Questions: 0Answers: 0
edited October 2010 in General
Hi there,

I'm wondering if it's possible to initialise DataTables on a table without using an ID for the table tag itself? I'm asking as I'm working with a CMS that has a certain type of table matrix field that I have no control over, so the best I can do is to surround the table in a div with a unique ID (it's otherwise well formatted, with a thead and tbody).

I was hoping to be able to use code like this to initialise it: $('#my-div table').dataTable... or $('table#my-div').dataTable...

But neither worked, so I thought I'd post to clarify that this won't work unless the table tag has an ID itself, or to find if there's another workaround for this.

Thanks for any help,

Stephen

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Certainly should work: http://datatables.net/examples/basic_init/multiple_tables.html . Any selector which returns the table you want will do it. As long as it returns the table element. alert( $('#my-div table').length ) will tell you how many elements were found.

    Allan
  • sm9sm9 Posts: 27Questions: 0Answers: 0
    Hi Allan,

    It now works! I'm not sure what went wrong the first time - probably a bug with your code... (joking!) :-)

    I actually suspect I put the div around an 'if statement' rather than the table between the if statement... :)

    Thanks,

    Stephen
This discussion has been closed.