基于 jQgrid 中给定条件的行之间的条件操作?

Conditional actions between rows based on a given condition in jQgrid?

我需要根据 jqGrid 4.4.1 网格中的给定条件在操作之间进行交换。看看下图:

它的工作原理是:

这就是我创建按钮的方式:

$.fn.fmatter.btnFormatter = function (cellValue, options, rowData, addOrEdit) {
    return '<a href="#">' +
        '<img class="api_button" data-id="' + options.rowId + '" src="/images/icons/16x16/document_view.png" alt="Show API Response Data" title="Show API Response Data" />' +
        '</a>' +
        '<a href="/sf/api-logs/error/' + options.rowId + '">' +
        '<img class="error_button" data-id="' + options.rowId + '" src="/images/icons/16x16/document_warning.png" alt="Show Errors" title="Show Errors" />' +
        '</a>';
};

$(function () {
    $("#grid").jqGrid({
        url: '/api-logs',
        datatype: "json",
        colNames: $('#colnames').data('values'),
        colModel: $('#colmodel').data('values'),
        width: 980,
        height: 300,
        pager: "#gridpager",
        toppager: true,
        hoverrows: true,
        shrinkToFit: true,
        autowidth: true,
        rownumbers: true,
        viewrecords: true,
        rowList: [10, 20, 50, 100],
        data: [],
        rownumWidth: 50,
        gridview: true,
        sortable: true,
        rowattr: function (item) {
            if (item.type === "api_response") {
                return {"class": "api_response"};
            } else if (item.type === 'api_request') {
                return {"class": "api_request"};
            }
        },
        jsonReader: {
            root: 'rows',
            page: 'page',
            total: 'total',
            records: 'records',
            cell: '',
            repeatitems: false
        }
    });
});

当然,第一列应用了 btnFormatter

我该怎么做?

您可以修改用于测试 rowData.type$.fn.fmatter.btnFormatter 代码,就像在 rowattr 回调中一样。

我强烈建议您以任何方式测试您现有的代码是否适用于当前版本的免费 jqGrid(版本 4.14.1)。您可以修改 3 行 HTML 代码并从 CDN 加载 CSS 和 JS 文件(参见 the wiki article)。 jqGrid 的 4.4.1 版本 dead。使用这么旧且不受支持的版本真的很危险。