extjs-以字母数字和不区分大小写的方式对存储进行排序 [英] extjs - Sort store alphanumerically and case insensitively

查看:146
本文介绍了extjs-以字母数字和不区分大小写的方式对存储进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想按字母顺序对存储(ArrayStore和GroupingStore)进行排序,并且不区分大小写.我正在使用singleSort()方法,但是区分大小写.

I want to sort store (ArrayStore and GroupingStore) alphanumerically and case INSENSITIVELY. I am using singleSort() method but it sorts case sensitively.

例如,

data = ['c', '1', 'A', 'a', 'C']
output = ['1', 'A', 'C', 'a', 'c']
myoutput = ['1', 'a', 'A', 'c', 'C'] or [['1', 'A', 'a', 'C', 'c']    // This is what I want

关于如何实现这一目标的任何建议?

Any suggestion on how to achieve this?

推荐答案

将此内容添加到您的代码中……请注意您的作用域,因为您将使页面上的所有类型都不区分大小写.我在论坛上找到了此代码,并已在3.2.1中成功使用了它.

Add this to your code... be wary of your scopes because you will make all sorts on the page case insensitive. I found this code on the forums and have used it successfully in 3.2.1.

Ext.data.Store.prototype.sortData = function(f, direction){
direction = direction || 'ASC';
var st = this.fields.get(f).sortType;
var fn = function(r1, r2) {
    var v1 = st(r1.data[f]), v2 = st(r2.data[f]);
    // ADDED THIS FOR CASE INSENSITIVE SORT
    if (v1.toLowerCase) {
        v1 = v1.toLowerCase();
        v2 = v2.toLowerCase();
    }
    return v1 > v2 ? 1 : (v1 < v2 ? -1 : 0);
};
this.data.sort(direction, fn);
if (this.snapshot && this.snapshot != this.data) {
    this.snapshot.sort(direction, fn);
}

}

这篇关于extjs-以字母数字和不区分大小写的方式对存储进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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