AJAX loads a pure HTML Table, how to send it to datatables

AJAX loads a pure HTML Table, how to send it to datatables

jgatringerjgatringer Posts: 2Questions: 1Answers: 0

Hallo and sorry for that noob question. I looked around here in the forum and cant find a solution for my problem.

I am a php developer with not much experience in javascript.

i do habe a ajax script, which is used in a wordpress page to load a table in an tab of the page.
The ajax script is working fine and delivers the table as it should. But i cant find a way to do the reformatting with datatables.

Here is my ajax script:
<script type="text/javascript"> <!-- function swapContent(cv1, cv2, cv3, cv4, cv5, cv6){ $("#standingsoutput").html('<img src="loader.gif">').show(); var url = "standingsloader.php"; $.post(url, {Var1: cv1, Var2: cv2, Var3: cv3, Var4: cv4, Var5: cv5, Var6: cv6},function(data){ $("#standingsoutput").html(data).show(); }); } --> </script>)

The standingsoutput is the div tag who will get the table (and refresh it with parameters). Is there a way to do format the table with datatables after reload the area with ajax, and before shows it on the page?

This question has an accepted answers - jump to answer

Answers

  • bindridbindrid Posts: 730Questions: 0Answers: 119
    Answer ✓

    If I understand you right, your ajax is returning a complete html table and not json data, which you are appending to a div. Assuming it is a complete table (not how I would do it), thein you can $("#standingsoutput").html(data).DataTable();

    In subsequent calls to get data, you have to destroy the DataTable before you call it again.

    You might also look up jquery.show, I don't think it is really doing anything in the current context.

  • jgatringerjgatringer Posts: 2Questions: 1Answers: 0

    Ok, thanks. I understand your hint with teh jquery and will try to do it that way.

This discussion has been closed.