[英]How to update data row in datatables
我想從數據庫中獲取值並通過條件顯示到數據表中,並且如果我更改輸入表單值(此輸入值是查詢的條件,因此如果我更改值,則數據表中的數據將更改),但是當我使用更改是有效的,但是當我嘗試兩次更改值時,他們說我要重新初始化,是否有任何建議可以解決問題?
我已經嘗試過該代碼,它可以工作,但是如果我再次更改該值,則會出現錯誤提示'DataTables警告:table id = dataTr-無法重新初始化DataTable。 有關此錯誤的更多信息,請參見http://datatables.net/tn/3
var asset = $('#formasset').find('input[name="ckdasset"]').val();
$(document).ready(function() {
$('#ckdasset').on('change',function(){
var dataTable = $('#dataTr').DataTable( {
"processing": true,
"ajax":{
url :"<?php echo base_url();?>index.php/Logged/get_detail_data/"+kode_asset_new+",
type: "post", // method , by default get
error: function(){ // error handling
$(".employee-grid-error").html("");
$("#dataTr").append('<tbody class="employee-grid-error"><tr><th colspan="3">No data found in the server</th></tr></tbody>');
$("#employee-grid_processing").css("display","none");
}
}
} );
});
} );
試試這個,您要重新初始化數據表,而不是重設/重畫。
var asset = $('#formasset').find('input[name="ckdasset"]').val();
$(document).ready(function () {
var dataTable = $('#dataTr').DataTable({
"processing": true,
"ajax": {
url: "<?php echo base_url();?>index.php/Logged/get_detail_data/" + kode_asset_new + ",
type: "post", // method , by default get
error: function () { // error handling
$(".employee-grid-error").html("");
$("#dataTr").append('<tbody class="employee-grid-error"><tr><th colspan="3">No data found in the server</th></tr></tbody>');
$("#employee-grid_processing").css("display", "none");
}
}
});
$('#ckdasset').on('change', function () {
var Dt = $('#dataTr').DataTable();
Dt.fnDraw();
});
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.