【问题标题】:tablesorter multiple dynamic tables on one parttablesorter 在一个部分上对多个动态表进行排序
【发布时间】:2014-04-09 23:21:37
【问题描述】:

嗨,我完全坚持这个。 我正在对从 mysql 数据库中提取的数据使用 tablesorter。 问题是,根据标准,我可以拉出并显示多个表格。

我的问题是 tablesorter 只会对第一个表实例进行排序。

这是我用于表格排序器的代码。基本使用。

<script type="text/javascript" >
$(document).ready(function()
{
$("#table-2").tablesorter();
}

这就是我提取数据并将其与 tablesorter 一起使用的方式。 可以更改的是分支名称。如果为用户分配了多个分支,他们将获得多个表。这就是我坚持在第一个实例之后的任何表上实现 tablesorter 的地方。

$result=mysql_query("SELECT id FROM users WHERE username='$username'");
$idary=mysql_fetch_assoc($result);
$id=$idary['id'];
$result0=mysql_query("SELECT branch_id FROM access WHERE userid='$id'");
while ($row1=mysql_fetch_assoc($result0))
{
$branch_id=$row1['branch_id'];
$result=mysql_query("select distinct(name) from location where id='$branch_id'");
$nameary=mysql_fetch_assoc($result);
$branchname=$nameary['name'];
?>
<table>
        <thead>
            <b><br><?echo $branchname; ?></b>
        </thead>
</table>
<div>
    <table id='table-2' class='tablesorter'>
        <thead>
            <tr>
                <thCreator</th>
                <th><center>TeamName</th>
                <th><center>Tech Tot</th>
                <th><center>Tot W/O</th>
                <th><center>Tot S/C</th>
            </tr>
        </thead>
    // get team creators from province
$result1=mysql_query("select distinct(teamcreator) from techteams where....

我想我需要使用某种形式的递增表名来匹配拉取的表数,但我一直不知道如何做到这一点。 我的假设可能是错误的,并且可能有更简单的方法来做到这一点。

如果有人对正确的方向有任何指示,我会喜欢一些提示。

干杯, -科林。

【问题讨论】:

    标签: javascript php jquery mysql tablesorter


    【解决方案1】:

    你可以尝试给你的表一个自己的类而不是一个 id。

    <table class='mytables'>
    
    <script type="text/javascript" >
    $(document).ready(function()
    {
      $(".mytables").tablesorter();
    }
    </script>
    

    或者也许只给他们 table-sorter 类,然后在你的脚本中尝试这样的事情:

    $("table").tablesorter();
    

    【讨论】:

    • +1 虽然,我不会使用$("table"),因为上面的标记有一个表,只有一个标题,可能不应该是可排序的。
    【解决方案2】:

    试试看:

    $(".tablesorter").tablesorter();
    

    【讨论】:

    • 直到我看到它类似地写在下面,我才知道这一点。非常感谢您的回复!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多