![](/img/trans.png)
[英]get the id of selected datatable row and pass it through a function for multiple row deletion
[英]Pass row ID of jquery datatable through column render to another function
伙计们,请帮我解决这个问题,我试图在jquery数据表中添加一个“编辑”按钮,并在每次用户单击时传递行ID,事实是,每次单击它时,它都说“未定义”,已经尝试了所有方法,但仍然缺少某些功能!
这是我的代码:
function LoadDtPrimaryBottom(JsonData) {
debugger;
var table = $('.dtPrimaryBottom').DataTable({
// dom: "Bfrtip",
"lengthMenu": [[6], [7]],
paging: true,
columns:[
{ title: 'Student ID', data: 'stu_ID'},
{ title: 'Registration No', data: 'Registration No' , 'searchable':true},
{ title: 'Name', data: 'Name' },
{ title: 'FathersName', data: 'FathersName' },
{ title: 'Class', data: 'Class' },
{ title: 'Section', data: 'Section' },
{
//"title": "Actions",
//"mdata": null,
//"render": function (data, type, row) {
// return '<button class="btnID">Edit</button>';
//"mData": null,
//"bSortable": false,
//"mRender": function (stu_ID) { return '<input id="btnDispose" type="button" onclick="myfunction(' + stu_ID +')" value="Edit" />'; }
'data': 'stu_ID',
'render': function (data, type, row) {
var id = $(this).data('stu_ID');
return '<input id="btnEdit" type="button" onclick="myfunction(' + id + ')" value="Edit" />';
}
}
],
data: JsonData
});
function myfunction(stu_ID){
debugger;
alert(stu_ID);
}
您的数据将直接显示在该函数的“数据”参数中。
'render': function (data, type, row) {
console.log(data)
return '<input id="btnEdit" type="button" onclick="myfunction(' + data + ')" value="Edit" />';
}
您可以使用它来获取所需的ID。
如果需要该对象的其他属性,则可以使用row。 它给出了整个行对象
尝试以下代码:
'render': function (data, type, row) {
var id =data; // You can also write this line like var id =row[0];
return '<input id="btnEdit" type="button" onclick="myfunction(' + id + ')" value="Edit" />';
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.