繁体   English   中英

根据另一列值禁用 jqgrid 中的超链接

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM