首页 > 代码库 > dataTables获取当前行json格式数据

dataTables获取当前行json格式数据

装载表格数据

 1 $(document).ready( function () {
 2      //页面加载后装载表格数据
 3     var table =  $(‘#mytable‘).DataTable( {
 4         "sProcessing": "处理中...",
 5              "ajax": {
 6                  "url": "/contact/getTableDatas",
 7              },
 8              "columns": [
 9                  { "data": "index",
10                   "render": function(data,type,row,meta){
11                     var startIndex = meta.settings._iDisplayStart;  
12                     return startIndex + meta.row + 1;  
13                   }
14                   },
15                  { "data": "name"},
16                  { "data": "state",
17                   "render":function(data,type,row){
18                         return "<button class=‘btn btn-danger‘ id=‘delete‘ name=‘delete‘ style=‘margin-left:10px;‘>删除</button>";
19 
20                   }
21                   }
22              ],
23          } );

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

1  $(document).on("click","#delete",function(e){
2       var rowdata = http://www.mamicode.com/table.row($(this).closest(‘tr‘)).data();
3      
4     });

 

dataTables获取当前行json格式数据