[英]Disable hyperlink in jqgrid based on another column value
I have a jqgrid where the first column has some number which is a hyperlink.我有一个 jqgrid,其中第一列有一些数字,它是一个超链接。 On click i am using
formatter:linkfmatter
and sending the rowid to the back end using ajax call.单击时,我正在使用
formatter:linkfmatter
并使用 ajax 调用将 rowid 发送到后端。
Now my requirement is if column B
is 0 i want the column A
to be a hyperlink but when the Column B
of that particular row is 1 i want Column B
hyperlink to be disabled.现在我的要求是,如果
B
列是 0,我希望A
列是超链接,但是当该特定行的B
列是 1 时,我希望B
列超链接被禁用。
Can someone tell me if it is possible at all using javascript-jquery and point me in right direction?有人可以告诉我是否可以使用 javascript-jquery 并指出我正确的方向吗? Here is my Code for the jqgrid
这是我的 jqgrid 代码
$("#tblJQGridCCVT").jqGrid({
url: "@Url.Action("MyAction", "MyController")" + "?Parameters=" + Params + "",
datatype: "json",
mtype: 'GET',
cache: false,
async: false,
colNames: ['A', 'B', 'C', 'D', 'E','F', so on...],//nearly 30 columns
colModel: [
{ name: 'A', index: 'A', width: 150, edittype: 'select', formatter: linkFmatter },
{ name: 'B', index: 'B', width: 150 },
{ name: 'C', index: 'C', width: 150 },
{ name: 'D', index: 'Updated By', width: 150 },
{ name: 'E', index: 'E', width: 150 },
{ name: 'F', index: 'F', width: 150 },
So on
...
...
...
],
pager: $('#pager'),
height:300,
rowNum: 10,
sortorder: "desc",
sortname: 'ResponseId',
viewrecords: true,
sortable: true,
loadonce: true,
forceClientSorting: true,
ignoreCase: true,
caption: "Summary"
});
$("#tblJQGridCCVT").jqGrid('navGrid', '#pager', { view: false, del: false, add: false, edit: false, search: true, refreshtext: "Refresh" }, { closeOnEscape: true, multipleSearch: true, closeAfterSearch: true }, {}, {}, {});
$("#tblJQGridCCVT").jqGrid('filterToolbar', { stringResult: true, searchOnEnter: false, defaultSearch: 'cn' });
function linkFmatter(cellvalue, options, rowObject) {
var selectedCellValue = cellvalue;
var selectedRowId = options.rowId;
return '<a href="javascript:MethodJS(' + selectedRowId + ')" style="color: #3366ff" id="' + selectedRowId + '" >' + selectedCellValue + '</a>';
}
function MethodJS(selectedRowId) {
$.ajax({
async: false,
type: "POST",
contentType: "application/json; charset=utf-8",
url: "@Url.Action("GetDetailedViewOfResponsesForEdit", "ViewResponseDetailsCCVT")",
data: "{RowId:'" + selectedRowId + "'}",
success: function (Result) {
if (Result == "Success") {
var url = window.location.href;
window.location.href = "@Url.Action("ResponseDetailsEditForCCVT", "ViewResponseDetailsCCVT")";
}
}
});
}
You have row data in rowObject
parameter.您在
rowObject
参数中有行数据。 You can use this like following.您可以像下面这样使用它。
function linkFmatter(cellvalue, options, rowObject) {
if (rowObject.B == 0) {
var selectedCellValue = cellvalue;
var selectedRowId = options.rowId;
return '<a href="javascript:MethodJS(' + selectedRowId + ')" style="color: #3366ff" id="' + selectedRowId + '" >' + selectedCellValue + '</a>';
}
return cellvalue
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.