[英]How to refresh datatable on changing the data without refreshing the whole page?
我有用于构建表的HTML / PHP代码:
echo '<table id="table" >';
echo '<thead>';
echo '<tr>';
echo '<th>#</th>';
echo '<th>Name</th>';
echo '<th>Location</th>';
echo '<th>Website</th>';
echo '<th>Actions</th>';
echo '</tr>';
echo '</thead>';
echo '<tbody id="tableContent">';
//Loop Through The Database Returned Data.
foreach($values as $val){
echo '<tr>';
echo '<td>' . $val['id'] . '</td>';
echo '<td>' . $val['name'] . '</td>';
echo '<td>' . $val['location'] . '</td>';
echo '<td> . $val['website'] . </td>';
echo '<td>
<button>Edit</button>
<button>Delete</button>
</td>';
echo '</tr>';
}//End For Each.
echo '</tbody>';
echo '</table>';
然后,我有此Jquery代码来运行Datatable插件:
var table = $('#table').DataTable({
"lengthMenu": [[5, 10, 25, 50, 100, -1], [5, 10, 25, 50, 100, "All"]] ,
"autoWidth": true,
"responsive": true,
"lengthChange": true,
"ordering": true
});
有(ADD,Edit,Delete)按钮,它们可以工作,但是我必须刷新表才能看到更改。
我试过了
table.destroy();
table.draw();
但是新表只包含1个没有分页的页面,并且过滤(搜索)不起作用。
-如何刷新而不刷新整个页面?
-是否可以在刷新表之前保留相同的页面,进行过滤?
我假设您正在尝试查看网页中的更新表,而不是实际数据库。 在这种情况下,请尝试将所需的代码放入表单中,并让表单的动作像#这样:
<form action='#' method='POST'>
your code
maybe you'll let the user click a button too
</form>
希望能奏效!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.