jqGrid 格式化程序和可排序列 - 不排序

2024-01-03

我正在为 jqGrid columnModel 使用自定义格式化程序,但无法使用格式化程序函数进行排序。如果我删除格式化程序列排序正常。

jQuery("#listAgentOptions").jqGrid({
    height: 240,
    datatype: "local",
    colNames: [' ', 'First Name', 'Last Name', 'Role'],
    colModel: [
    { name: 'status', index: 'status', width: 18, sorttype: 'text', align: 'center', formatter: function(cellvalue, options, rowObject) {
        return cellvalue == 1 ? "<img src='images/agent_green_s.png' alt='Ready' title='Ready' />" :
        cellvalue == 3 ? "<img src='images/agent_red_s.png' alt='Busy' title='Busy' />" :
        "<img src='images/agent_orange_s.png' alt='Pending Ready' title='Pending Ready' />";
    },
        unformat:
    function(cellvalue, options, rowObject) { return Math.floor(Math.random() + 0.1).toString(); }
    },
    { name: 'firstName', index: 'firstName', width: 92 },
    { name: 'lastName', index: 'lastName', width: 142 },
    { name: 'role', index: 'role', sorttype: 'int', width: 36, align: 'center', formatter: function(cellvalue, options, rowObject) {
        return cellvalue == true ? "<img src='images/user_gray.png' alt='Supervisor' title='Supervisor' />" : "<img src='images/user.png' alt='Agent' title='Agent' />";
    }, unformat:
    function(cellvalue, options, rowObject) { return cellvalue; }
    }
    ],
    sortname: 'lastName'
});

行添加如下:

jQuery("#listAgentOptions").jqGrid('clearGridData');
$.each(result, function(i, item) {
    if (item.ContactType == 1) {
        jQuery("#listAgentOptions").jqGrid('addRowData', i+1, { firstName: item.ContactName.split(" ")[0], lastName: item.ContactName.split(" ")[1],
        role: item.IsSupervisor,
        status: item.Status == "Ready" ? 1 : item.Status == "Busy" ? 3 : 2
        });
    }
});

如何让排序正常工作?

Update.我刚刚下载了最新版本的 jqGrid - 同样的问题。

我也尝试过使用unformat: function(cellvalue, options, rowObject) { }但 cellvalue 那里是空的 :-E 当我使用return Math.floor(Math.random() + 0.1).toString();它确实随机排序(每次我点击),但是return cellvalue;仅返回一个空字符串。


在内部,jqGrid 使用unformat获取单元格的值:

        $.each(ts.rows, function(index, row) {
            try { sv = $.unformat($(row).children('td').eq(col),{rowId:row.id, colModel:ts.p.colModel[col]},col,true);}
            catch (_) { sv = $(row).children('td').eq(col).text(); }
            row.sortKey = findSortKey(sv);
            rows[index] = this;
        });

然后使用该列的处理程序解析单元格值sorttype,对于 int 的情况:

            findSortKey = function($cell) {
                return IntNum($cell.replace(stripNum, ''),0);
            };

所以基本上,如果你的unformat函数为每个单元格返回正确的整数,我希望列排序也能正常工作。如果您仍然遇到问题,请发布您的完整代码,包括以下内容unformat.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

jqGrid 格式化程序和可排序列 - 不排序 的相关文章

随机推荐