刚刚完成我的第一个html,将csv文件中的数据呈现给漂亮的表格。我现在的问题是我需要添加一行,并意识到:
<tfoot>
<tbody class="tablesorter-no-sort">
。我有什么方法可以设置添加或识别输出中的总计行? 谢谢,
作为参考,我的简单代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" type="text/css" href="../../js/ts/css/theme.default.css">
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript" src="../../js/ts/js/jquery.tablesorter.min.js"></script>
<script type="text/javascript" src="../../js/ts/js/jquery.tablesorter.widgets.min.js"></script>
<script type="text/javascript" src="../../js/csv/js/jquery.csvToTable.js"></script>
<script>
$(function() {
$('#myTable').CSVToTable('fam.txt',
{
startLine: 1,
separator: ";"
}
).bind("loadComplete",function() {
$(document).find('#myTable').tablesorter({sortList: [[0,0], [1,0]],widgets:
["zebra", "stickyHeaders"]});
});;
});
</script>
</head>
<body>
<table id="myTable" class="tablesorter">
</table>
</body>
</html>
答案 0 :(得分:2)
如果需要操作表,请在“loadComplete”事件函数中执行此操作。
试试这个:
$(function() {
var mytable = $('#myTable')
.CSVToTable('fam.txt',{
startLine: 1,
separator: ";"
})
.bind("loadComplete",function(){
var footer = mytable.find('tr:last');
// if you try to append a tr wrapped in a tfoot, jQuery will assume you are
// adding a tr and put it inside the tbody... so target the tfoot (parent)
mytable
.find('thead').after( footer.wrap('<tfoot/>').parent() ).end()
.tablesorter({
sortList: [[0,0], [1,0]],
widgets: ["zebra", "stickyHeaders"]
});
});
});