我有一个jquery datatable
,它会将数据带到表格中。现在每行都有一个update
按钮。单击其中将打开一个选项卡,其中包含相关数据。因此,为了获取当前行的单击值,我尝试了我的代码
function getDataForSMPS() {
var table = $('#grdSMPSRCOM').DataTable();
$('#example tbody').on('click', 'div', function () {
console.log(table.row(this).data());
});
}
但无法获取数据。
这是我的完整jquery数据表代码
var details = [];
for (var i = 0, len = retrievedParsedValue.length; i < len; i++) {
var result = retrievedParsedValue[i];
var buttonColumn = "<b><div style='cursor: pointer;' onClick=" + 'getDataForSMPS();' + ">Update</div></b>";
details.push([retrievedParsedValue[i]['RJ_FACILITY_ID'], retrievedParsedValue[i]['IID'], retrievedParsedValue[i]['SMPS_AVAILABLE'], retrievedParsedValue[i]['NO_OF_SMPS_ONSITE'], retrievedParsedValue[i]['SMPS_MAKE'], retrievedParsedValue[i]['SMPS_CAPACITY'], retrievedParsedValue[i]['CONTROLLER_MODEL'], retrievedParsedValue[i]['RECT_MODULE_MODEL'], retrievedParsedValue[i]['HEALTHY_RECTIFIER_COUNT'], retrievedParsedValue[i]['BACKPLANE_RECTIFIER_SLOT'], retrievedParsedValue[i]['RECT_CAPACITY'], retrievedParsedValue[i]['SMPS_STATUS'], retrievedParsedValue[i]['NO_OF_FAULTY_MODULES'], retrievedParsedValue[i]['DC_LOAD'], retrievedParsedValue[i]['SMPS_OTHER_REMARKS'], buttonColumn]);
}
$('#grdSMPSRCOM').DataTable({
destroy: true,
data: details,
"scrollX": true,
columns: [
{ title: "RJ_FACILITY_ID" },
{ title: "IID" },
{ title: "SMPS_AVAILABLE" },
{ title: "NO_OF_SMPS_ONSITE" },
{ title: "SMPS_MAKE" },
{ title: "SMPS_CAPACITY" },
{ title: "CONTROLLER_MODEL" },
{ title: "RECT_MODULE_MODEL" },
{ title: "HEALTHY_RECTIFIER_COUNT" },
{ title: "BACKPLANE_RECTIFIER_SLOT" },
{ title: "RECT_CAPACITY" },
{ title: "SMPS_STATUS" },
{ title: "NO_OF_FAULTY_MODULES" },
{ title: "DC_LOAD" },
{ title: "SMPS_OTHER_REMARKS" },
{ title: "Update Data" }
],
"bDestroy": true
});
答案 0 :(得分:1)
您使用了#example而不是grdSMPSRCOM,
试试这个,
var details = [];
for (var i = 0, len = retrievedParsedValue.length; i < len; i++) {
var result = retrievedParsedValue[i];
var buttonColumn = "<div class='edit_btn' style='cursor: pointer;' >Update</div>";
details.push([retrievedParsedValue[i]['RJ_FACILITY_ID'], retrievedParsedValue[i]['IID'], retrievedParsedValue[i]['SMPS_AVAILABLE'], retrievedParsedValue[i]['NO_OF_SMPS_ONSITE'], retrievedParsedValue[i]['SMPS_MAKE'], retrievedParsedValue[i]['SMPS_CAPACITY'], retrievedParsedValue[i]['CONTROLLER_MODEL'], retrievedParsedValue[i]['RECT_MODULE_MODEL'], retrievedParsedValue[i]['HEALTHY_RECTIFIER_COUNT'], retrievedParsedValue[i]['BACKPLANE_RECTIFIER_SLOT'], retrievedParsedValue[i]['RECT_CAPACITY'], retrievedParsedValue[i]['SMPS_STATUS'], retrievedParsedValue[i]['NO_OF_FAULTY_MODULES'], retrievedParsedValue[i]['DC_LOAD'], retrievedParsedValue[i]['SMPS_OTHER_REMARKS'] + buttonColumn]);
}
$('#grdSMPSRCOM').DataTable({
destroy: true,
data: details,
"scrollX": true,
columns: [
.....
],
"bDestroy": true
});
var table = $('#grdSMPSRCOM').DataTable();
$('#grdSMPSRCOM').on('click', 'tbody .edit_btn', function () {
var data_row = table.row($(this).closest('tr')).data();
console.log(data_row);
} );