tablesorter cannot read property '0' of undefined with data
-
19-10-2022 - |
Question
Hi I have a table dynamicaly filled (via php and jquery) but the tablesorter does not work Scripts initialization at the end of the page
<!-- JavaScript -->
<script src="js/bootstrap.js"></script>
<!-- Page Specific Plugins -->
<script src="js/tablesorter/jquery.tablesorter.js"></script>
<script src="js/tablesorter/tables.js"></script>
<script>
function dynamicRefresh()
{
//generic
$(".pm-count").load("php-scripts/dynamic/pm-system/countU.php");
$(".pm-ddmenu").load("php-scripts/dynamic/pm-system/menu.php");
$(".com-count").load("php-scripts/dynamic/com-system/countU.php");
$(".com-ddmenu").load("php-scripts/dynamic/com-system/menu.php");
//Page Specific
var lpage = page - 1;
$("#new_msg").load("php-scripts/data/setlist/table.php", {'page':lpage});
//Refresh Rate
setTimeout("dynamicRefresh()",60000);
}
window.onload=dynamicRefresh;
</script>
Table Code
<table class="table table-hover table-striped tablesorter">
<thead>
<tr>
<th>Ordem # <i class="fa fa-sort"></i></th>
<th>Nome <i class="fa fa-sort"></i></th>
<th>Banda <i class="fa fa-sort"></i></th>
<th>Original/Cover <i class="fa fa-sort"></i></th>
<th>Acção <i class="fa fa-sort"></i></th>
</tr>
</thead>
<tbody id="new_msg">
</tbody>
</table>
I only click to sort the table when the table is filled with data I know if the table has no data this error occurrs. Can it be because of the plugin initialization? The plugin is loaded faster then the table data.
UPDATE #1
After close look at the debug console I see this
Built headers:,1ms jquery.tablesorter.js:147
[th.header, th.header, th.header, th.header, th.header, prevObject: x.fn.x.init[1], context: table.table.table-hover.table-striped.tablesorter, selector: "thead th", jquery: "1.10.2", constructor: function…]
I think it's safe to assume that when the plugin is initialized it builds the headers but also loads the data to faster sorting, if this is correct is there a function to "update" the initialization process?
UPDATE 2
After reading some more I found that I just need to add a trigger in this case
$('.tablesorter').trigger('update');
It's working fine now
No correct solution