How do I implement custom sort to a specific column after jqgrid has been generated?(生成 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 后如何实现对特定列的自定义排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:生成 jqgrid 后如何实现对特定列的自定义排序?
				
        
 
            
        基础教程推荐
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
 - 如何使用 CSS 显示和隐藏 div? 2022-01-01
 - jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
 - 如何在特定日期之前获取消息? 2022-01-01
 - 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
 - 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
 - WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
 - Node.js 有没有好的索引/搜索引擎? 2022-01-01
 - Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
 - 每次设置弹出窗口的焦点 2022-01-01
 
    	
    	
    	
    	
    	
    	
    	
    	
						
						
						
						
						
				
				
				
				