Table with data via ajax


Is there any way to have a table with dynamic data or data loaded with an Ajax request?


I would use a data-binding framework like knockoutjs to bind the table contents to a list of items in your model. That works like a charm.



Yes. I do it via ajax all the time. There are two ways I do it and it depends on whether I am using the SUI table sort plugin. If I don’t need sorting I build the whole table in php and then insert it directly into an html element, usually a div. All of SUI’s table classes work on dynamic tables. If I need sorting I create the table (everything but body) in html and then build the table’s rows in php. I then insert the rows into an empty body tag via ajax. The table sort plugin doesn’t work on dynamically created tables. There is probably a way to reinitiize a dynamic table but haven’t been able to figure out how to make it work that way.

php code-build out your table rows like this:
$html_table .= ‘

$html_table .= ‘creator’;
$html_table .= ‘’ . $row[‘id’] . ‘’;
$html_table .= ‘’;

insert the php into the html table framework:



oops. it deleted the code. see if this works. i removed the caret symbols. code is a bit harder to read.

php table rows:

$html_table .= ‘tr’;
$html_table .= ‘td’ id /td’;
$html_table .= ‘td’ . $row[‘id’] . ‘/td’;
$html_table .= ‘/tr’;

insert the php into the html table framework:

th id /th
tbody id=“Insert php data here”