1
我在CodeIgniter的控制器中使用Ajax
来获取dataTable
行。数据表在使用ajax加载行时对数据表进行任何操作后数据丢失
我已经取得了它的成功,但问题是行在数据表上做任何操作时会丢失,如sorting
,searching
。 但刷新页面后,它回来了。
这里是我的Ajax脚本:
$('#dataTable_choose').DataTable({
responsive: true
});
$('body').on('click', '.getJobApplication', function(e) {
//alert();
var noteId = $(this).data('noteId');
var note_id = { id : noteId }
$.ajax({
type: 'POST',
async: true,
dataType: 'Json',
url: get_table_rows,
data: note_id,
success: function (response) {
if(response.length > 0){
for (i = 0; i < response.length; i++) {
innerhtml += "<tr>" +
"<td>"+response[i].column1+"</td>" +
"<td>"+response[i].column2+"</td>" +
"<td>"+response[i].column3+"</td>" +
"<td>"+response[i].column4+"</td>" +
"<td><span class='label label-info'>"+column5+"</span></td>" +
"<td>"+
"<button type='button' class='btn btn-success waves-effect waves-light' data-secid="+response[i].id2+" " +
" data-fiid = "+response[i].id+" >Choose</button>" +
"</td>" +
"</tr>";
$('#table_body').html(innerhtml);
}
} else {
console.log('error');
}
},
error: function (msg)
{
console.log('error');
}
});
});
这里是表HTML
代码:
<table id="dataTable_choose" class="table table-striped table-bordered dt-responsive nowrap" cellspacing="0" width="100%">
<thead>
<tr>
<th>Job Title</th>
<th>Qualification</th>
<th>Qualification Major</th>
<th>Candidate Name</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody id="table_body">
</tbody>
</table>
感谢您的回答,先生,但它如何能工作,我点击获取数据表行,它只发生一次。所以当我试图对表格中的任何东西进行“搜索”或“排序”时,get再次消失。 –
你试过了吗?你在萤火虫 - >控制台或其他方面有任何错误吗? – GeorgeGeorgitsis
好吧,先生我已经尝试解决'排序'问题解决了,但'搜索'不起作用。 –