Undermine2k
Undermine2k

Reputation: 1491

PHP dynamically generated table and jquery tablesorter

I have a table that's being generated with PHP

<table id="mytable" class="tablesorter tablesorter-jui ui-widget ui-widget-content ui-corner-all hasStickyHeaders">
<thead style="">//code for headers </thead>
<tbody>
<?php 
foreach ($active_participants as $participant) 
{
//code for rows..
}
?>
</tbody>
</table>

I am applying the jquery tablesorter plugin to it, however it does not sort(no jquery errors). I need it to display on page load, because it's the first thing the user will see, however can I have it wait for the page to finish loading before applying

 $("#myTable").tablesorter({ sortList: [[0,0], [1,0]] });

what is the proper way to do this?

Upvotes: 0

Views: 1897

Answers (2)

user2658774
user2658774

Reputation: 146

You would want to do this in the documents ready function. So in the head section of your html just add:

<script type="text/javascript">
$(document).ready(function() {
    $("#myTable").tablesorter({ sortList: [[0,0], [1,0]] });
});
</script>

That will run once the document is fully loaded.

EDIT: Reyaner Beat me to the answer. :)

Upvotes: 2

reyaner
reyaner

Reputation: 2819

did you try this:

$(document).ready(function(){
    $("#myTable").tablesorter({ sortList: [[0,0], [1,0]] });
});

Upvotes: 0

Related Questions