var pincode=$(this).closest('tr').children('td.pincode').text();
上面的代码适用于非响应数据表
但它在数据表的响应视图中不起作用是否有任何替代解决方案
table = $('#example').DataTable({
"data": arr,
"iDisplayLength": 10,
"pagingType": "simple_numbers",
"bDestroy": true,
/* responsive: {
details: {
type: 'column',
target: 'tr'
}
},*/
responsive: true,
columnDefs: [
/*{
className: 'control',
orderable: false,
targets: 0,
visible:true
},*/
{
responsivePriority: 1,
targets: 1
},
{
"aTargets": [0],
"sTitle": "Id",
"class": "Id",
"bSortable": true
},
{
"aTargets": [1],
"sTitle": "name",
"class": "name",
"bSortable": true
},
{
"aTargets": [2],
"sTitle": "gender",
"class": "gender",
"bSortable": true
},
{
"aTargets": [3],
"sTitle": "pincode",
"class": "pincode",
"bSortable": true
},
{
"aTargets": [4],
"sTitle": "City",
"class": "City",
"bSortable": true
},
{
"aTargets": [5],
"sTitle": "Action",
"bSortable": true,
"render": function(data, type, row) {
var returnHTML = CreateDataHTML(data);
return returnHTML;
}
}
],
order: [1, 'asc']
});
答案 0 :(得分:0)
通过查看您的datatable
初始化代码,您可以尝试下面的代码。假设你的代码行是在每个数据表行中存在的按钮的按钮处理程序代码中的某处写的:
var data = table.row( $(this).parents('tr') ).data(); //current row data
var pincode = data[3]; //pin code is at index 3
这应该适用于响应式和非响应式场景。