jqgrid按文本排序列 [英] jqgrid sorting column by text issue

查看:76
本文介绍了jqgrid按文本排序列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的网站上使用了jqgrid并且遇到了一个问题

I have used jqgrid in my site and am getting one problem here

我做了什么:

{name: 'type', index: 'type', width: 40, editable: true,edittype:"select",sorttype: "text", editoptions:{value:"1:Article;2:Seminar;3:Research;4:Cases"}},

现在网格排序按ID而不是此列的文字
所以个案最后会因为其ID为4

now grid sort by id not by text for this column so "Cases" appears at last due to its id 4

所以如何排序按文字列?

so how to sort this column by text?

推荐答案

解决问题的最简单方法是使用 sorttype 定义为函数。您可以创建对象或数组,使选择值映射到相应的文本,并将选择值替换为 sorttype 内的文本。如果在排序期间将使用 sorttype 返回的文本而不是值:

The most easy way to solve the problem would be usage of sorttype defined as function. You can create object or array which makes mapping of select value to the corresponding text and replace the select value to the text inside of sorttype. In the case the text returned by sorttype will be used during sorting instead of the value:

var typeMapping = {
        "1": "Article",
        "2": "Seminar",
        "3": "Research",
        "4": "Cases"
    };

...

{ name: 'type', width: 40, editable: true,
    edittype: "select", editoptions: {value: "1:Article;2:Seminar;3:Research;4:Cases"},
    sorttype: function (value) {
        return typeMapping[value];
    }}

相应的演示使用上面的代码,它显示以下排序结果:

The corresponding demo uses the above code and it displays the following sorted results:

这篇关于jqgrid按文本排序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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