简体   繁体   English

生成jqgrid后,如何对特定列实现自定义排序?

[英]How do I implement custom sort to a specific column after jqgrid has been generated?

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)? 在使用javascript(jQuery)填充后,是否有一种方法可以用来为colModel中的特定列重写/插入自定义函数“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. 我在这里找到了一个例子: http ://www.ok-soft-gmbh.com/jqGrid/CustomSorttype1.htm,其中sorttype是用初始设置实现的,但我之后需要更改它。

Tried: 尝试:

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

but doesn't work. 但不起作用。

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'. 使用sorttype作为函数对于jqGrid的任何本地数据类型或者在使用loadonce:true情况下都是loadonce:true jqGrid paremter与“remote”数据类型'json'或'xml'。 If it is needed you can change the sorttype of any column dynamically. 如果需要,您可以动态更改任何列的sorttype

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

where grid is $("#list") . grid$("#list")

If one click on the checkbox one more time the original sorting method with sorttype:"text" will be used. 如果再次单击该复选框,将使用具有sorttype:"text"的原始排序方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使jqgrid列排序? - How do I make jqgrid columns sort? 如何检查特定模块是否已添加到 Worklet? - How do I check if a specific module has been added to a Worklet? 如何在通过Ajax生成表单后显示验证 - How to display validation after the form has been generated via Ajax 如何对已经渲染的集合进行排序? 就像AngularJS的orderBy指令 - How do I sort a collection that has already been rendered? Like AngularJS's orderBy directive 如何使用jqGrid区分大小写? - How do I sort case-insensitively with jqGrid? 特定模型更新后,如何让keystoneJS运行函数? - How do I get keystoneJS to run a function once a specific model has been updated? 如何让angular知道自定义窗口事件已被触发并需要更新检查 - How do I let angular know a custom window event has been fired and requires update checking 如何显示刚刚在jqGrid中更新的保存值,而无需重新加载整个网格? - How can I show a saved value that has just been updated in a jqGrid without reloading the entire grid? 如何设置doubleClick函数以在jqGrid中调用自定义函数 - How do I set doubleClick function to call custom function in jqGrid 如何使用自定义按钮发送到JQGrid的editurl? - How do i use a custom button to send to the JQGrid's editurl?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM