2017-02-16 84 views
1

我使用jquery数据表绑定我的json数据并在行上添加按钮。现在我怎样才能通过按钮点击获得列表上的特定列数据?我可以得到一个行值,但无法找到获取列值的方法。jquery datatable:通过按钮点击获取整个列值

这是我的代码:

$.ajax({ 
    url: "SympsService.asmx/GetSymptoms", 
    method: "post", 
    dataType: "json", 
    data: JSON.stringify({ organ_name: "toes" }), 
    contentType: "application/json", 
    success: function (data) { 
     var sympList = 'GetSymptoms' ? JSON.parse(data.d) : data.d; 
     createDataTable('#symptomsTable', sympList); 

     function createDataTable(target, data) { 
      $(target).DataTable({ 
       destroy: true, 
       paging: false, searching: false, info: false, data: data, 
       columnDefs: [{ 
        targets: [-1], render: function() { 
         return "<button type='button'>" + ('Choose') + "</button>" 
        } 
       }], 
       columns: [{ 
         'data': 'Sympt', 
         'title': 'toes Symptoms',}, 
       {'data': null, 'title': 'Action' }] 
       }); 
     } 
     $('#symptomsTable').on("click", "tbody button", function() { 
      var id = $(this).closest("tr").find("td:nth-child(1)").data(); 
      //here i get every row data by button click 
      //but i want specific column data on list 
     }) 
    } 
}); 

回答

0

试试这个,可以帮助你。

$('#table tbody').on('click', 'td', function() { 
    var index = $(this).index(); 
    var column = $('#table').column(index); 
}); 
+0

使用console.log('column')时显示未捕获的类型错误.column不是函数。 @ saf21 –