Forum

November 2nd, 2014
A A A
Avatar

Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

The forums are currently locked and only available for read only access
sp_Feed Topic RSS sp_Related Related Topics sp_TopicIcon
Searching on text field with accentued chars on local datas
01/01/2011
20:23
Avatar
olaf
GRENOBLE (FRANCE)
Member
Members
Forum Posts: 27
Member Since:
08/01/2010
sp_UserOfflineSmall Offline

How to ignore case and accentued chars searching on local datas (after a loadonce: true;)

02/01/2011
14:06
Avatar
OlegK
Germany
Member
Members
Forum Posts: 1255
Member Since:
10/08/2009
sp_UserOfflineSmall Offline

Try to use ignoreCase:true option of jqGrid.

02/01/2011
17:11
Avatar
olaf
GRENOBLE (FRANCE)
Member
Members
Forum Posts: 27
Member Since:
08/01/2010
sp_UserOfflineSmall Offline

Thank you Oleg,

This option is already set to true and searching is not case sensitive;

But it does'not solve searching on accentued chars;

Example : local searching "benevise" do not find "bénevise"; json data is "B\u00e9nevise"

Happy New Year

04/01/2011
18:04
Avatar
OlegK
Germany
Member
Members
Forum Posts: 1255
Member Since:
10/08/2009
sp_UserOfflineSmall Offline

Hi Olaf,

your question is difficult, but I found it interesting. So I prepared the demo which demonstrate the idea, how to solve the problem. Try to search in the grid for the string benevise and you will find also the string bénevise.

Of cause the replacement of accentuated characters in the string is not supported directly. So to solve the problem I made following. I replace _getStr method of the $.jgrid.from:

$.jgrid.from = function(source,initalQuery){
    var result = oldFrom(source,initalQuery);
    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;
}

where global function myAccentRemovement is defined as following

function myAccentRemovement(s) {
    // the s parameter is always string
    return s.replace(/[èéêë]/gi,'e');
}

Of cause you can include the code inside of _getStr function instead of myAccentRemovement call, but I made so in case of more complex implementation of the accent replacement.

To understand the solution I describe the main idea how the local searching work. The standard implementation of the local searching create string like

"(String(this.name) == String("benevise"))"

in case of "equal to" operation or

"(String(this.name).indexOf("benevise",0) > -1)"

in case of "contain" operation.

Then inside of execute function (see here) will be the above string executed with respect of eval JavaScript function:

$.each(_data,function(){
   if(eval(match)){results.push(this);}
});
_data=results;

After the modification of _getStr function the code like

"(myAccentRemovement(String(this.name)) == myAccentRemovement(String("benevise")))"

will be executed.

Modifying my example you can implement practically any custom local searching/filtering.

Best regards
Oleg

12/02/2011
12:05
Avatar
olaf
GRENOBLE (FRANCE)
Member
Members
Forum Posts: 27
Member Since:
08/01/2010
sp_UserOfflineSmall Offline

Oleg,

sorry to answer so late to your suggestion;

I try your demo at : http://www.ok-soft-gmbh.com/jq.....Search.htm

It is OK for : Client begin with béne -> and find bénevise and benevise

It is not OK for : Client contains béne -> and find NOTHING.

12/02/2011
14:50
Avatar
OlegK
Germany
Member
Members
Forum Posts: 1255
Member Since:
10/08/2009
sp_UserOfflineSmall Offline

Hi Olaf,

In the previous example I wanted mostly show how one can overwrite methods from $.jgrid.from. If you try to search in my first example for: Client contains 'bene' instead of 'béne' you will find the both lines. So the problem is just in the additional conversion of the input line with the respect of myAccentRemovement function.

To fix the problem in the previous example one can just add some additional lines in the code and overwrite additionally the _toStr method:

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;
}

You can see live here that the new example work with "contain", "start with" or other operations.

Best regards
Oleg

12/02/2011
16:39
Avatar
olaf
GRENOBLE (FRANCE)
Member
Members
Forum Posts: 27
Member Since:
08/01/2010
sp_UserOfflineSmall Offline

Oleg

Wonderful and thank you for your amazing work.

Best regards

Olivier

14/02/2011
19:49
Avatar
olaf
GRENOBLE (FRANCE)
Member
Members
Forum Posts: 27
Member Since:
08/01/2010
sp_UserOfflineSmall Offline

Oleg,

for the same grid my datas are ordered on geographics points'name.

The accentued char É is at the end of the list.

Abri Vallot

Aiguille de l'Epaisseur

.........

Ecole

Emeindras de dessus

Engins

..........

Villard-de-Lans

Villeneuve-la-Salle

Évisa

--- End of the list

it is not UTF8 ordered

Thank for any help.

14/02/2011
20:26
Avatar
OlegK
Germany
Member
Members
Forum Posts: 1255
Member Since:
10/08/2009
sp_UserOfflineSmall Offline

It is less complex problem as before. You can use sorttype as function. See the new demo. Try to sort ba 'Client'.

Best regards
Oleg 

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

Currently Online:
55 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

OlegK: 1255

markw65: 179

kobruleht: 144

phicarre: 132

YamilBracho: 124

Renso: 118

Member Stats:

Guest Posters: 447

Members: 11373

Moderators: 2

Admins: 1

Forum Stats:

Groups: 1

Forums: 8

Topics: 10592

Posts: 31289

Newest Members:

, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.com

Moderators: tony: 7721, Rumen[Trirand]: 81

Administrators: admin: 66

Comments are closed.
Privacy Policy   Terms and Conditions   Contact Information