AJAX returns table can I apply DataTables to it?

AJAX returns table can I apply DataTables to it?

chicheemochicheemo Posts: 4Questions: 0Answers: 0
edited February 2012 in General
Hi,

I have a ajax call that based on the user input generates 2 HTML tables that are returned inside a DIV. Is there a way to apply DataTables on one of the returned tables? Perhaps there is an easier way of doing this that I'm not yet aware of? I'm very new to DataTables so I apologize if my answer is obvious.

Cheers,
Addison

Replies

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    [code]
    $('selector-for-the-table').dataTable();
    [/code]

    :-). Obviously you would need to use a suitable selector...

    Allan
  • chicheemochicheemo Posts: 4Questions: 0Answers: 0
    edited February 2012
    Thanks Allan that was rather silly of me.

    What if I return any number of tables back? All the ones that I want to apply dataTabes to have the same selector value, as I mentioned before they are generated based on what the user selects.

    Thanks for your help!
    Addison
  • chicheemochicheemo Posts: 4Questions: 0Answers: 0
    More specifically I want to generate a dataTable for anything with the selector value:

    [code] $('#bookData').dataTable( );[/code]
  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    There can only be one element with that selector (since it is an ID). DataTables doesn't have a "live" type operator where it will initialise tables that match the given selector in future - the element needs to be on the page at the time of initialisation.

    Allan
  • chicheemochicheemo Posts: 4Questions: 0Answers: 0
    Thanks for the clearing that one up Allan.

    I'm sure there is a way to do this, suppose I have an unique id at the end of each selector that might look like:

    [code]$('#bookDatalz1w6cDKQk').dataTable( );[/code]

    Where the suffix could be any random set characters. Is there a way I can initialise a DataTable for each one without knowing the exact selector value. Something along the lines of a foreach loop perhaps? I've been messing around with it for sometime but haven't gotten anywhere yet.

    I really appreciate your help. You have been very patient with my troubles... :-D

    Addison
This discussion has been closed.