问题描述
我已使用此 ignited_datatables
在我的 CodeIgniter项目
中。它从数据库
成功返回数据
。但是主要的问题
是,当我添加新记录
时,新插入的数据未显示在表<$中c $ c>自动,当我刷新
页面时,新插入的
数据为然后显示在表
中。因此我想通过 ajax
自动显示该数据,而不必。
I Have used this ignited_datatables
https://github.com/IgnitedDatatables/Ignited-Datatables in my CodeIgniter project
. It successfully returns data
from the database
. But the main problem
is that when I add a new record
the newly inserted data is not shown in the table automatically
and when I refresh
the page then the newly inserted
data is then shown in the table
. so I want to show that data automatically through ajax
and I have not to refresh
the page.
我的视图
<div class="box-body table-responsive">
<table id="Slider_table" class="table table-bordered table-hover">
<thead>
<tr>
<th>ID</th>
<th>Title</th>
<th>item_Price</th>
<th>Description</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div><!-- /.box-body -->
此脚本在视图内
$(document).ready(function() {
$("#Slider_table").dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxDataProp": "data",
"fnServerData": function(sSource, aoData, fnCallback){
$.ajax({
"dataType": "json",
"type" : "POST",
"url" : "'.base_url().'Home/items_list/list",
"data" : aoData,
"success" : function(res){
fnCallback(res);
}
});
}
});
});
推荐答案
我认为您需要使用 draw( )方法,以便更新表的显示。
I think you need to use draw() method after success in order to have the table's display updated.
table.row.add( {
//you dynamic data
"name": "Tiger Nixon",
"position": "System Architect",
"salary": "$3,120",
"start_date": "2011/04/25",
"office": "Edinburgh",
"extn": "5421"
} ).draw();
根据文档。请参考
这篇关于如何在Codeigniter的数据表中发送Ajax请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!