[英]Disable hyperlink in jqgrid based on another column value
我有一個 jqgrid,其中第一列有一些數字,它是一個超鏈接。 單擊時,我正在使用formatter:linkfmatter
並使用 ajax 調用將 rowid 發送到后端。
現在我的要求是,如果B
列是 0,我希望A
列是超鏈接,但是當該特定行的B
列是 1 時,我希望B
列超鏈接被禁用。
有人可以告訴我是否可以使用 javascript-jquery 並指出我正確的方向嗎? 這是我的 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")";
}
}
});
}
您在rowObject
參數中有行數據。 您可以像下面這樣使用它。
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.