0
私はhtmlテーブルにソート可能な列を追加しようとしていますが、jquery tablesorterに試してみると思いました。これは私の構文で実際のDB呼び出しを避けるためのものですが、テーブルを適切に設定したと思いますが、テーブルでは並べ替えができません。なぜソートできないのですか?TableSorterでHTMLテーブルを並べ替え
<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 --->
私はこのように読むために、私の構文を編集し、それでも以下の問題
</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
は$query
が、それはだのを取得する方法を示すために更新されてい値
<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>
@spiral_generatorと同じように、テーブルをソートしたい場合は 'print"
";' foreach'ループの外側に移動してください。元のtablesorterを使用している場合、すべての「余分な」tbodyは完全に無視されます。私の[tablesporterのfork](https://mottie.github.io/tablesorter/docs/)を使用している場合、それぞれのtbody内の行は独立してソートされます。 – Mottie答えて
1つしか必要ありませんそれぞれの開閉タグが付いているので、ループを
foreach
ループから移動する必要があります。出典
2017-06-26 19:06:53
私の編集を参照してください...私はそれを試し、まだ運がないと思う。 – BellHopByDayAmetuerCoderByNigh
ちょうどtablesorterドキュメントを見ました。実際には、 '/ path/to/jquery-latest.js'と'/path/to/jquery.tablesorter.js'という2つのjavascriptプラグインを含めましたか?それらを適切なファイルパスに置き換える必要があります。また、あなたのHTMLには '
'タグがありません。 –LOL - 私はそれを実際のパスに変更しました。上の例のようにそのまま残しました。うーん...ボディータグを追加して、それがdiffを作るかどうかを見てみましょう。 bodyタグに追加すると差分はありません – BellHopByDayAmetuerCoderByNigh
関連する問題