Table with data via ajax


#1

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


#2

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.

–j.


#3

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:

id

#4

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:

table
thead
tr
th id /th
/tr
/thead
tbody id=“Insert php data here”
/tbody
tfoot
/tfoot
/table