在单元格上单击jQuery Datatable按钮,获取所有行单元格的值



我的jQuery Datatable有以下代码,其中最后一列有一个按钮。当用户单击它时,我需要获取所有列单元格值,以便将它们传递到模态中进行编辑。

"fnDrawCallback": function (oSettings) {
hideWaiting();
// button to Edit the person
$('[data-id="btnedit"]').on('click', function (e) {
var me = $(this);
e.preventDefault();
var personId = $(this).attr('data-personid');

//*** HERE I WANT TO GET ALL ROW CELLS VALUES ***//
$this.showEditModal();
});
},
"aoColumns": [
{ "sName": "Description", "bSortable": true },
{ "sName": "Name", "bSortable": true },
{ "sName": "Position", "bSortable": false },
{ "sName": "ContentUrl", "bSortable": false },
{ "sName": "HolidayType", "bSortable": false },
{ "sName": "LeaveType", "bSortable": false },
{
"mData": null,
"bSortable": false,
"sWidth": "80px",
"sClass": "dt-body-center",
"mRender": function (data, type, row) {
var res = "";
res = '<a href="#" data-id="btnedit" data-personid="' + row[6] + '" data-toggle="tooltip" data-placement="top" title="" class="btn btn-primary"><i class="fa fa-pencil"></i></a>';
return res;
}
},

也许有类似的东西

res = '<a href="#" data-id="btnedit" data-personid="' + row[6] + '" data-toggle="tooltip" data-placement="top" title="" class="btn-get-row btn btn-primary"><i class="fa fa-pencil"></i></a>';
$(document).ready( () => {
$('.btn-get-row').click( (e) => {
let myCells = $(this).closest('tr').find('td');
let data = { 
description: myCells[0].innerHTML,  // or myCells[0].find('input').val();
name: myCells[1].innerHTML // or myCells[1].find('input').val();
// ... and so on
}
})
})

最新更新