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

查看:128
本文介绍了生成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 带有remote数据类型'json'或'xml'的jqGrid paremter。如果需要,您可以动态更改任何列的 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我们勾选设置自定义排序类型功能复选框,网格将按照下一张图片显示进行排序

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;
    }
}

和复选框上的'change'事件处理程序

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天全站免登陆