dataTables获取当前行json格式数据

时间:2022-07-24 01:18:28

装载表格数据

 $(document).ready( function () {
//页面加载后装载表格数据
var table = $('#mytable').DataTable( {
"sProcessing": "处理中...",
"ajax": {
"url": "/contact/getTableDatas",
},
"columns": [
{ "data": "index",
"render": function(data,type,row,meta){
var startIndex = meta.settings._iDisplayStart;
return startIndex + meta.row + 1;
}
},
{ "data": "name"},
{ "data": "state",
"render":function(data,type,row){
return "<button class='btn btn-danger' id='delete' name='delete' style='margin-left:10px;'>删除</button>"; }
}
],
} );

删除按钮绑定事件,获取该行数据

  $(document).on("click","#delete",function(e){
var rowdata = table.row($(this).closest('tr')).data(); });