我刚开始使用jqGrid,我想使用自定义删除按钮删除行.我正在使用下面的代码段:
try {
var cellValue;
var id;
jQuery("#editDataGridList").jqGrid({
datatype: "local",
width: 900,
height: 270,
colNames: ['Action', 'Interview id', 'Date of observation', 'Name of enumerator'],
onSelectRow: function (id) {
debugger;
var rowData = jQuery(this).getRowData(id);
cellValue = rowData['InterviewId'];
},
colModel: [
{
name: 'actions', index: 'InterviewId', sortable: false,
formatter: function (rowId, cellval, colpos, rwdat, _act) {
return "<input type='button' id='btnid' value='delete' class='btn' onClick='deleteRecords(" + cellValue + ");' />";
}
},
{ name: 'InterviewId', index: 'InterviewId' },
{ name: 'Date', index: 'Date' },
{ name: 'NameOfEnum', index: 'NameOfEnum' }
],
multiselect: false,
caption: "Edit already entered data"
});
}
catch (e) {
alert(e.message);
}
Run Code Online (Sandbox Code Playgroud)
上面的代码使用此函数调用来传递所选的行值以进行删除
function deleteRecords(rowData) {
alert(rowData);
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,rowData值未定义.如何使用相同的结构删除行?
Waq*_*mon 10
你可以删除行使用
$('#editDataGridList').jqGrid('delRowData',rowid);
Run Code Online (Sandbox Code Playgroud)
我找到了解决我自己问题的方法。
formatter: function (rowId, cellval, colpos, rwdat, _act) {
var rowInterviewId = colpos.InterviewId.toString();
return "<input type='button' id='" + rowInterviewId + "' value='delete' class='btn'
onClick='deleteRecords(this)' />";
}
Run Code Online (Sandbox Code Playgroud)
我只是将其作为参数传递给按钮 onclick 事件,在函数调用中,它具有按钮所需的所有属性,但最重要的一个是按钮 id,它是按钮所属行的访谈 id。