how to do local search on formatted column value in jqgrid?

前端 未结 1 720
长情又很酷
长情又很酷 2020-12-06 23:18

I\'m using loadonce to get all data up front and then doing sorting and filtering locally.

One of my column values is an array of objects. In the colModel option I u

相关标签:
1条回答
  • 2020-12-06 23:29

    In my old answer in the trirand forum I described how to implement custom local filtering and sorting. The demo shows accent free searching and sorting. If you use the same technique you can overwrite some jqGrid functions used for searching (_toStr and _getStr for example) and implement it so that in case of arrays you will use your own it's implementation.

    To make my answer more Google friendly I include small code fragment

    function myAccentRemovement(s) {
        // the s parameter is always string
        s = s.replace(/[àáâãäå]/gi,'a');
        s = s.replace(/[èéêë]/gi,'e');
        s = s.replace(/[ìíîï]/gi,'i');
        s = s.replace(/[òóôõöø]/gi,'o');
        s = s.replace(/[ùúûü]/gi,'u');
        s = s.replace(/[ýÿ]/gi,'y');
        s = s.replace(/æ/gi,'ae');
        s = s.replace(/œ/gi,'oe');
        s = s.replace(/ç/gi,'c');
        s = s.replace(/š/gi,'s');
        s = s.replace(/ñ/gi,'n');
        s = s.replace(/ž/gi,'z');
        return s;
    }
    //...
    var oldFrom = $.jgrid.from;
    $.jgrid.from = function(source,initalQuery){
        var result = oldFrom(source,initalQuery);
        var old_toStr = result._toStr;
        result._toStr=function(s) {
            return myAccentRemovement(old_toStr(s));
        };
        result._getStr=function(s) {
            var phrase=[];
            if(this._trim){
                phrase.push("jQuery.trim(");
            }
            phrase.push("myAccentRemovement(String("+s+"))");
            if(this._trim){
                phrase.push(")");
            }
            if(!this._usecase){
                phrase.push(".toLowerCase()");
            }
            return phrase.join("");
        }
        return result;
    }
    

    It will be solve the problem. I can't gives you more exact suggestions because you posted no information about the exact structure of data which you use.

    0 讨论(0)
提交回复
热议问题