dongzhangji4824 2017-06-26 19:01
浏览 41

使用TableSorter对HTML表进行排序

I am attempting to add sortable columns to my html table and I thought I would give the jquery tablesorter a try. This is my syntax sans the actual DB call, and I think I have it set-up properly, however my table is not allowing me to sort. Why am I not able to sort?

    <head>
<script type="text/javascript" src="/path/to/jquery-latest.js"></script> 
<script type="text/javascript" src="/path/to/jquery.tablesorter.js"></script> 
<script>
    $(document).ready(function() 
    { 
        $("#SaleDistro").tablesorter(); 
    } 
); 
</script>
</head>

<table id="SaleDistro" class="tablesorter" border="1">
<thead>
<tr>
<th>Sales Name </th>
<th>Sales Region </th>
<th>Sales Count </th>
<th>Sales Supervisor </th>
</tr>
</thead>
<?php
foreach ($query as $res) 
{
print "<tbody>";
print "<tr>";
print "<td>" . $res->sn . "</td>";
print "<td>" . $res->sr . "</td>";
print "<td>" . $res->sc . "</td>";
print "<td>" . $res->ss . "</td>";
print "</tr>";
print "</tbody>";
}
?>
</table>
</html>

EDIT --->
I edited my syntax to read like this, but still have the issue

</thead>
<tbody>
<?php
foreach ($query as $res) 
{
print "<tr>";
print "<td>" . $res->sn . "</td>";
print "<td>" . $res->sr . "</td>";
print "<td>" . $res->sc . "</td>";
print "<td>" . $res->ss . "</td>";
print "</tr>";
}
?>
</tbody>
</table>
</html>

EDIT 2
Below is update to show how $query get's it's value

    <head>
<script type="text/javascript" src="/path/to/jquery-latest.js"></script> 
<script type="text/javascript" src="/path/to/jquery.tablesorter.js"></script> 
<script>
    $(document).ready(function() 
    { 
        $("#SaleDistro").tablesorter(); 
    } 
); 
</script>
</head>
<?php
    $option = array();
    $option['driver'] = 'mssql';
    $option['host'] = 'IP Address';
    $option['user'] = 'username';
    $option['password'] = 'password';
    $option['database'] = 'database';
    $option['prefix'] = '';
    $db = JDatabase::getInstance($option);
    $query = $db->getQuery(true);
    $query = "Select SalesName, SalesRegion, SalesCount, SalesSupervisor from salesdata;";
    $db->setQuery($query);
    $query = $db->loadObjectList();
    if ($query) 
    {
?>
<table id="SaleDistro" class="tablesorter" border="1">
    <thead>
    <tr>
        <th>Sales Name </th>
        <th>Sales Region </th>
        <th>Sales Count </th>
        <th>Sales Supervisor </th>
    </tr>
    </thead>
<?php
foreach ($query as $res) 
{
    print "<tbody>";
    print "<tr>";
    print "<td>" . $res->sn . "</td>";
    print "<td>" . $res->sr . "</td>";
    print "<td>" . $res->sc . "</td>";
    print "<td>" . $res->ss . "</td>";
    print "</tr>";
    print "</tbody>";
}
?>
</table>
</html>
  • 写回答

1条回答 默认 最新

  • dongzhi6087 2017-06-26 19:06
    关注

    You only want one <tbody> opening and closing tag each, so you need to move them out of the foreach loop.

    评论

报告相同问题?

悬赏问题

  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了
  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能