[jQuery] jquery and sortable table
Hi,
I notice when I load a page and perform the following call
<code>
var str = "";
$.ajax( {
url: 'core/getIngredients.php',
type: 'POST',
data: str,
success: function(xml) {
$(xml).find("table").each(function() {
var t = $(this).text();
var table = $("#list_ingredients");
$("#list_ingredients tr").each(function() {
if($(this).attr("id").indexOf("tr") >= 0) {
$("#" + $(this).attr("id")).remove();
}
});
table.append(t);
});
}
} );
</code>
it works just fine and populates this table
<code>
<table id="list_ingredients" cellspacing="2" cellpadding="0"
class="list_ingredients2">
<thead>
<tr>
<th>Ingredient</th>
<th>Action</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
If i try to get the jquery sort to work on top of this call, it won't
notice the table
has values and gives a parser error. I can code around the parser
error with
<code>
$('#list_ingredients:has(tbody tr)').tablesorter({
sortList:[[0,0]], widgets: ['zebra']});
</code>
My question is if you run a jquery call to load a table when the page
loads, how do you
get the jquery.tablesorter to understand the table is populated.
If I do inline population of the table via php mysql_query and loop
structures, it works fine.
I'd rather have jquery do the call at the time of loading so I can
separate out my presentation and logic. Any thoughts would be grately
appreciated.
J