生成 jqgrid 后如何实现对特定列的自定义排序? [英] How do I implement custom sort to a specific column after jqgrid has been generated?

查看:17
本文介绍了生成 jqgrid 后如何实现对特定列的自定义排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用 javascript (jQuery) 填充 colModel 中的特定列后,我可以使用一种方法覆盖/插入自定义函数sorttype"吗?

Is there a method I can use to over-write/insert a custom function "sorttype" for a specific column in the colModel after it has been populated using javascript (jQuery)?

我在这里找到了一个例子:http://www.ok-soft-gmbh.com/jqGrid/CustomSorttype1.htm,其中 sorttype 是使用初始设置实现的,但之后我需要更改它.

I've found an example here: http://www.ok-soft-gmbh.com/jqGrid/CustomSorttype1.htm, where sorttype is implemented with the initial settings, but what I need to change it after.

试过了:

var attName = grid.getGridParam("colModel")[1].name;
        grid.setColProp(attName, { sorttype: function (cell) {
            if (cell == '<div>x</div>') { return '0' } else { return '1' };
        }
        });

但不起作用.

推荐答案

sorttype 作为函数的使用对于 jqGrid 的任何本地数据类型或在使用 loadonce 的情况下都有用:true 带有远程"数据类型json"或xml"的 jqGrid 参数.如果需要,您可以动态更改任何列的 sorttype.

The usage of sorttype as the function can be useful for any local datatype of jqGrid or in case of the usage loadonce:true jqGrid paremter with the "remote" datatypes 'json' or 'xml'. If it is needed you can change the sorttype of any column dynamically.

我为您制作了新演示来演示该功能.开始时,网格将按客户端"列排序,包含的列将被解释为文本字符串.结果如下所示

I made the new demo for you to demonstrate the feature. At the begining the grid will be sorted by 'Client' column and the column contain will be interpret as the text string. The results are displayed below

我们勾选设置自定义排序功能"复选框,网格将按照下一张图片显示的方式进行排序

Wenn we check the checkbox "Set custom sorttype function" the grid will be sorted as displayed on the next picture

为了实现这种排序,我定义了函数

To implement such sorting I defined the function

var myCustomSort = function(cell,rowObject) {
    if (typeof cell === "string" && /^test(d)+$/i.test(cell)) {
        return parseInt(cell.substring(4),10);
    } else {
        return cell;
    }
}

以及复选框上的更改"事件处理程序

and the 'change' event handler on the checkbox

$("#customsorttype").change(function() {
    var isChecked = $(this).is(':checked');
    if (isChecked) {
        cm.sorttype = myCustomSort;
    } else {
        cm.sorttype = "text";
    }
    grid.trigger("reloadGrid");
});

其中 grid$("#list").

如果再次单击复选框,将使用原始排序方法 sorttype:"text".

If one click on the checkbox one more time the original sorting method with sorttype:"text" will be used.

这篇关于生成 jqgrid 后如何实现对特定列的自定义排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆