gpt4 book ai didi

javascript - JQuery Datatable 仅适用于空(无数据)表

转载 作者:行者123 更新时间:2023-12-02 23:15:06 25 4
gpt4 key购买 nike

当表为空时,数据表工作并显示没有可用数据(页面和搜索等。)但是当插入一行时,数据表中断。我使用 PHP 将数据获取到表中,并且过去曾使用过此方法并且工作正常。

我假设由于它适用于空表,因此问题不在于脚本等的链接。任何帮助都会很棒,谢谢。

我尝试通过更正标签等来查看 HTML 中是否存在问题,但我似乎无法识别问题。

<div class="tab-pane active" id="queries">
<hr>
<table id="table1" class="table table-striped ">
<thead>
<tr class="sticky" >
<th>Date of Complaint</th>

<th>Reference</th>
<th>Name</th>
<th>Surname</th>

<th>Subject</th>


<th> </th>


</tr>
</thead>
<?php
//process $result

echo "<tbody>";


while ($row = mysqli_fetch_assoc($queriesresult2)) {
;
echo "<tr>";

echo "<td>".$row['Data1']."</td>";
echo "<td>".$row['Data2']."</td>";
echo "<td>".$row['Data3']."</td>";
echo "<td>".$row['Data4']."</td>";
echo "<td>".$row['Data5']."</td>";

echo "<td><a class=\"btn btn-danger\" href=\"editQUERY?id=".$row['id']."\">Edit</a></td>";

echo "</tr>";


}


echo "</tbody>";


?>
</table>

<hr>

</div>

最佳答案

我看到您使用引导dataTables。尝试这个代码,它应该可以工作,并且您将拥有搜索栏:

<html>
<head>
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.css">
<script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.js"></script>

<div class="tab-pane active" id="queries">
<hr>
<table id="example" class="display" width="100%">
<thead>
<tr>
<th>Name</th>
<th>Position</th>
<th>Office</th>
<th>Extn.</th>
<th>Start date</th>
<th>Salary</th>
</tr>
</thead>
<tbody>
<?php while ($row = mysqli_fetch_assoc($queriesresult2)) { ?>
<tr>
<td><?= $row['data1'] ?></td>
<td><?= $row['data2'] ?></td>
<td><?= $row['data3'] ?></td>
<td><?= $row['data4'] ?></td>
<td><?= $row['data5'] ?></td>
<td><a class="btn btn-danger" href="editQUERY?id="<?= $row['id'] ?>">Edit</a></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
<script>

$(document).ready(function() {
$('#example').DataTable( {} );
} );
</script>
</body>
</html>

关于javascript - JQuery Datatable 仅适用于空(无数据)表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57196426/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com