[英]JQuery Datatable add new row,if the row is already present remove it and insert new row for that ID
Tried to remove rows using following method 尝试使用以下方法删除行
table.DataTable().row().remove().draw();
I tried add using the following methods 我尝试使用以下方法添加
1) table.dataTable().fnAddData(jsonObject);
1)
table.dataTable().fnAddData(jsonObject);
2) table.DataTable().row.add(jsonObject).draw();
2)
table.DataTable().row.add(jsonObject).draw();
Add is not working, it is removing the old data and again after redraw it is showing old data in that row. 添加不起作用,它正在删除旧数据,并且在重绘后再次在该行中显示旧数据。
At first i am making ajax call and fetching data from database after that i need to add data in client side without making ajax call. 首先,我要进行ajax调用并从数据库中获取数据,之后我需要在客户端进行数据添加而不进行ajax调用。
this.updateTableandMap=function(jsonObject){
if(jsonObject!=null){
var curTimeStamp=$('tr#'+jsonObject.trackeeId+'>td:eq(0)>a').attr('data-date-time-stamp');
if(jsonObject.dateAndTime>curTimeStamp){
$('#records-short').DataTable().row( $('#records-short>tbody>tr#'+jsonObject.trackeeId+'')).remove().draw();
// $('#records-short').DataTable().row.data(jsonObject).draw();
// $('#records-short').dataTable().fnAddData(jsonObject);
}else if(curTimeStamp==undefined){
$('#records-short').DataTable().row( $('#records-short>tbody>tr#'+jsonObject.trackeeId+'')).remove().draw();
$('#records-short>tbody>tr#'+jsonObject.trackeeId+'').remove();
$('#records-short').DataTable().row.add(jsonObject).draw();
}
}
};
you can try this way in your script 您可以在脚本中尝试这种方式
var row = $(this).closest('tr');
$('.dataTable').dataTable().fnDeleteRow(row);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.