分组时忽略大小写 [英] Ignore case while grouping

查看:75
本文介绍了分组时忽略大小写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法告诉jqGrid在分组时忽略大小写?我不想更改数据,因为有些将是大写,有些是小写,而有些则是混合大小写.

Is there a way to tell the jqGrid to ignore the case while grouping? I don't want to change the data as some will be upper case, some lower case and others mixed case.

我正在使用jqGrid 4.4.4

I'm using jqGrid 4.4.4

推荐答案

问题很好,但是...当前在jqGrid中分组的实现只允许对 exact 值进行分组.我记得有人要求按月分组而不是按确切日期分组时的严格要求.

The question is good, but ... the current implementation of grouping in jqGrid allow grouping only exact values. I remember close requirements when one wanted to group by month instead by exact date.

在对jqGrid的源代码进行了分析之后,我希望我找到了一种非常简单且非常灵活的方式来进行更灵活的分组.我建议修改该行

After some analyse of the source code of jqGrid I hope that I found very simple and very flexible way to do more flexible grouping. I suggest to modify the line

if( typeof v !== "object" && grp.lastvalues[i] !== v ) {

if (typeof v !== "object" &&
        ($.isFunction(grp.isInTheSameGroup) ?
            !grp.isInTheSameGroup(grp.lastvalues[i], v) :
            grp.lastvalues[i] !== v)) {

此后,可以在groupingView内部定义isInTheSameGroup函数:

After this one can define isInTheSameGroup function inside of groupingView:

grouping: true,
groupingView: {
    ...
    groupField: ["name"], // the column by which we group
    isInTheSameGroup: function (x, y) {
        return String(x).toLowerCase() === String(y).toLowerCase();
    }
}

该演示显示以下结果:

我在jqGrid 4.4.5的jquery.jqGrid.src.js的演示修改版中使用了.修改jqGrid 4.4.4的jquery.jqGrid.src.js版本的方式与您可以找到

I used in the demo modified version of jquery.jqGrid.src.js of jqGrid 4.4.5. The version of jquery.jqGrid.src.js of jqGrid 4.4.4 modified in the same way you can find here.

我稍后将我的建议发布给trirand.我希望jqGrid的下一个版本将包含该功能.

I will post later my suggestion to trirand. I hope that the next version of jqGrid will contain the feature.

已更新:按照承诺,我发布了

UPDATED: As promised, I posted the corresponding feature request to trirand.

更新2 :我发布了拉动请求对jqGrid的分组模块进行了更多更改. 该演示演示了如何使用新功能.它使用2级分组,并显示以下结果:

UPDATED 2: I posted the pull request with a little more changes of grouping module of jqGrid. The demo demonstrates how new features can be used. It uses 2-level grouping and displays the following results:

更新3 :我提出的拉取请求发送给trirand的内容现在合并到jqGrid的主要代码中.因此,下一版本的jqGrid(在4.4.5之后)将支持groupingView中的isInTheSameGroupformatDisplayField回调数组.如果您的情况看起来像是

UPDATED 3: The pull request which I sent to trirand is merged now to the main code of jqGrid. So the next version of jqGrid (after 4.4.5) will supports isInTheSameGroup and formatDisplayField arrays of callbacks inside of groupingView. If your case it would look like

groupingView: {
    groupField: ['name'],
    formatDisplayField: [
        function (displayValue) { //, value, cm, index, grp) {
            return String(displayValue).toLowerCase();
        }
    ],
    groupColumnShow: [true],
    groupDataSorted: true,
    isInTheSameGroup: [
        function (x, y) {
            return String(x).toLowerCase() === String(y).toLowerCase();
        }
    ]
}

通过groupField[0]分组将使用回调isInTheSameGroup[0]formatDisplayField[0].因为jqGrid支持多级分组,所以isInTheSameGrouformatDisplayField属性是回调函数的数组,而不仅仅是回调函数.

The callbacks isInTheSameGroup[0] and formatDisplayField[0] will be used by grouping by groupField[0]. Because jqGrid support multilevel grouping the isInTheSameGrou and formatDisplayField properties are arrays of callback functions instead of just callback function.

在按分组列对 jqGrid排序数据进行分组的开始.可以使用定义为函数的sorttype来定制第一步(请参见答案).我不打算写你的答案.可能使用sorttype: function (cellvalue) {return String(cellvalue).toLowerCase();}已经可以解决您的问题.

At the beginning of grouping jqGrid sort data by grouping column. One can use sorttype defined as function to customize the first step (see the answer). I don't though about the step during writing of your answer. Probably usage of sorttype: function (cellvalue) {return String(cellvalue).toLowerCase();} could already solve your problem.

然后将使用功能isInTheSameGroup[level]将上一行的分组列的值与当前行的对应值进行比较.函数isInTheSameGroup[level]将使用这些值进行调用.如果您的回调返回true,则该行将与上一行分组.

Then the function isInTheSameGroup[level] will be used consequently to compare the value of grouping column from of previous row with the corresponding value of the current row. The function isInTheSameGroup[level] will be called with the values. If your callback returns true then the row will be grouped with the previous one.

回调formatDisplayField[level]允许自定义分组标题中显示的信息.在上面的示例中,我将数据转换为小写字母.

The callback formatDisplayField[level] allows to customize the information displayed in the grouping header. In the example above I convert the data to low case.

这篇关于分组时忽略大小写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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