我有一个jqGrid,它有一个包含"编辑"按钮的操作列。和"删除"。要求是用户点击"删除"操作列中的按钮。该行未删除,但标记为要删除。因此,我的实现是删除"编辑"按钮并替换"删除"按钮"未删除"按钮。以下是代码
jQuery('#grid').jqGrid({
datatype: 'local',
colNames:[
'action',
... other columns
],
colModel:[
{ name:'action', formatter:actionLink, align:'center', sortable:false, width:150},
... other columns
],
height: 'auto',
width: 935
});
function actionLink(cellvalue, options, rowObject) {
var editImg = '<img width="16" height="16" border="0" alt="Edit" src="${contextPath}/images/edit.png">';
var deleteImg = '<img width="16" height="16" border="0" alt="Delete" src="${contextPath}/images/delete.png">';
var editLink = '<a href="javascript:void(0)" onclick="edit(' + options.rowId + ');">' + editImg + '</a>';
var deleteLink = '<a href="javascript:void(0)" onclick="delete(' + options.rowId + ');">' + deleteImg + '</a>';
return editLink + ' ' + deleteLink;
}
function delete(rowId) {
var selectedObj = jQuery('#rid').jqGrid('getRowData', rowId);
var unDeleteImg = '<img width="16" height="16" border="0" src="${contextPath}/images/arrow_undo.png" />';
selectedObj.action = '<a href="javascript:void(0)" onclick="unDelete(' + rowId + ');">' + unDeleteImg + '</a>';
jQuery('#grid').jqGrid('setRowData', rowId, selectedObj);
}
操作列仍会显示&#34;编辑&#34;和&#34;删除&#34;按钮而不仅仅是&#34;撤消&#34;按钮。我做错了什么?这是格式化函数actionLink的问题吗?
答案 0 :(得分:0)
您可以访问jqgrid行,如下面的代码
for (var i = 0; i < gridData.length; i++) {
var row = $("#grdGridView").jqGrid('getRowData', gridData[i]);
var item = gridData[i]["chkSelect"];
jQuery("#grdGridView").jqGrid('setCell', i + 1, 2, '', { color: 'black' });
if ($(item).prop("checked") == true) {
var o = {};
o.GridViewkey = gridData[i]["GridViewkey"];
o.GridViewDesc = gridData[i]["GridViewDesc"];
o.LocationStatus = gridData[i]["LocationStatus"];
o.EffectiveDate = $(gridData[i]["EffectiveDate"]).prop("value");
o.InactivationDate = $(gridData[i]["InactivationDate"]).prop("value");
if (!validatedt(o.EffectiveDate) && o.EffectiveDate != "" && !validatedt(o.InactivationDate) && o.InactivationDate != "") {
msg = msg + "[" + o.GridViewDesc + "]: Date is invalid. <br/>";
jQuery("#grdGridView").jqGrid('setCell', i + 1, 2, '', { color: 'red' });
}
else if (!validatedt(o.EffectiveDate) && o.EffectiveDate != "") {
msg = msg + "[" + o.GridViewDesc + " Effective Date]: Date is invalid. <br/>";
jQuery("#grdGridView").jqGrid('setCell', i + 1, 2, '', { color: 'red' });
}
else if (!validatedt(o.InactivationDate) && o.InactivationDate != "") {
msg = msg + "[" + o.GridViewDesc + " Term Date]: Date is invalid. <br/>";
jQuery("#grdGridView").jqGrid('setCell', i + 1, 2, '', { color: 'red' });
}
o.rid = i + 1;
params[i] = o;
}
}