Forum
21:40
11/01/2011
Currently the sorttype property of a column defines the type of the column for appropriate sorting.
Possible values include int/integer - for sorting integer ; float/number/currency - for sorting decimal numbers ; date - for sorting date and text - for text sorting.
I have a need for case, punctuation and accent insensitive text sorting.
For example, currently jqGrid sorts a column in this order:
- ...
- Cross-border reorganization
- Crystallization of...
- Crédit d'impôt ...
- ...
- Draft Guidance on ...
- Dubai Investment
- Décisions récentes
- ...
- Lutte contre les planifications fiscale
- L’Institut des Cadres Fiscaliste: ...
- Majoration fiscale ...
- ...
- World Tour ...
- École de hautes ...
- ...
The requirement is to have a sortable column in this order:
- ...
- Crédit d'impôt ...
- ...
- Cross-border reorganization
- Crystallization of...
- ...
- Décisions récentes
- ...
- Draft Guidance on ...
- Dubai Investment
- ...
- École de hautes ...
- ...
- L’Institut des Cadres Fiscaliste: ...
- ...
- Lutte contre les planifications fiscale
- Majoration fiscale ...
- ...
- World Tour ...
- ...
00:38
10/08/2009
Hello McCulloch,
jqGrid have a nice posibility to define some properties as functions. For example the sorttype property of the colModel can be also defined as function with the prototype sorttype: function(cellValue, rowObject) {/* return some value which will be used in compare operations */}. I hope that the implementation of sorttype can solve your problem
cellValue = cellValue.replace(/[àáâãäå]/gi,'a');
cellValue = cellValue.replace(/[èéêë]/gi,'e');
cellValue = cellValue.replace(/[ìíîï]/gi,'i');
cellValue = cellValue.replace(/[òóôõöø]/gi,'o');
cellValue = cellValue.replace(/[ùúûü]/gi,'u');
cellValue = cellValue.replace(/[ýÿ]/gi,'y');
cellValue = cellValue.replace(/æ/gi,'ae');
cellValue = cellValue.replace(/œ/gi,'oe');
cellValue = cellValue.replace(/ç/gi,'c');
cellValue = cellValue.replace(/š/gi,'s');
cellValue = cellValue.replace(/ñ/gi,'n');
return cellValue.replace(/ž/gi,'z');
}
Best regards
Oleg
16:45
11/01/2011
Thank you Oleg, this approach worked but the specific function did not. It probably had something to do with character encoding. Here is the function that ended up working for me, after researching UTF-8 encoding:
{
var r = s.toLowerCase();
var diacritics = [
[/[\\u00E0-\\u00E5]/gi, 'a'],
[/\\u00E6/gi, 'ae'],
[/\\u00E7/gi, 'c'],
[/[\\u00E8-\\u00EB]/gi, 'e'],
[/[\\u00EC-\\u00EF]/gi, 'i'],
[/\\u00F0/gi, 'd'],
[/\\u00F1/gi, 'n'],
[/[\\u00F2-\\u00F6,\\u00F8]/gi, 'o'],
[/[\\u00F9-\\u00FC]/gi, 'u'],
[/[\\u00FD,\\u00FF]/gi, 'y'],
[/\\u00DF/gi, 'ss']
];
for (var i = 0; i < diacritics.length; i++)
{
r = r.replace(diacritics[i][0], diacritics[i][1]);
}
return r;
}
Thanks for the help.
17:46
10/08/2009
Hi,
if you save the file which contain the JavaScript code (JS or HTM file) in UTF-8 encoding all work. You can try the demo which I created before for the answer. The demo do even more as you asked.
Best regards
Oleg
01:29
09/12/2011
Hi Oleg,
I have had some good success with using sorttype: function(cellValue, rowObject) as you describe. The value which is returned from the function seems to be compared as a String however, and in some cases I would like it to be compared as an int, or date, or some other datatype without having to convert those to sortable String equivalents.
Do you have any idea how to do this, as in how to indicate in the sorttype function how the returned value should be interpreted in a sort?
Thanks,
Nolan
Most Users Ever Online: 715
Currently Online:
59 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.comModerators: tony: 7721, Rumen[Trirand]: 81
Administrators: admin: 66