【问题标题】:Disable hyperlink in jqgrid based on another column value根据另一列值禁用jqgrid中的超链接
【发布时间】:2017-05-26 05:50:19
【问题描述】:

我有一个 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")";
            } 
        }
    });
}

【问题讨论】:

    标签: javascript jquery asp.net-mvc jqgrid


    【解决方案1】:

    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
    }
    

    DEMO HERE

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-08-23
      • 1970-01-01
      • 1970-01-01
      • 2020-11-01
      • 2013-08-31
      • 1970-01-01
      • 2017-12-31
      相关资源
      最近更新 更多