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_TopicIcon
text sorttype enhancement
11/04/2011
21:40
Avatar
McCulloch
Toronto, ON, CA
Member
Members
Forum Posts: 6
Member Since:
11/01/2011
sp_UserOfflineSmall Offline

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:

  1. ...
  2. Cross-border reorganization
  3. Crystallization of...
  4. Crédit d'impôt ...
  5. ...
  6. Draft Guidance on ...
  7. Dubai Investment
  8. Décisions récentes
  9. ...
  10. Lutte contre les planifications fiscale
  11. L’Institut des Cadres Fiscaliste: ...
  12. Majoration fiscale ...
  13. ...
  14. World Tour ...
  15. École de hautes ...
  16. ...

The requirement is to have a sortable column in this order:

  1. ...
  2. Crédit d'impôt ...
  3. ...
  4. Cross-border reorganization
  5. Crystallization of...
  6. ...
  7. Décisions récentes
  8. ...
  9. Draft Guidance on ...
  10. Dubai Investment
  11. ...
  12. École de hautes ...
  13. ...
  14. L’Institut des Cadres Fiscaliste: ...
  15. ...
  16. Lutte contre les planifications fiscale
  17. Majoration fiscale ...
  18. ...
  19. World Tour ...
  20. ...
12/04/2011
00:38
Avatar
OlegK
Germany
Member
Members
Forum Posts: 1255
Member Since:
10/08/2009
sp_UserOfflineSmall Offline

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

sorttype: function(cellValue) {
    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

12/04/2011
16:45
Avatar
McCulloch
Toronto, ON, CA
Member
Members
Forum Posts: 6
Member Since:
11/01/2011
sp_UserOfflineSmall Offline

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:

sorttype: function(cellValue) { return removeDiacritics(cellValue); }

function removeDiacritics(s)
{
    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.


12/04/2011
17:46
Avatar
OlegK
Germany
Member
Members
Forum Posts: 1255
Member Since:
10/08/2009
sp_UserOfflineSmall Offline

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 

09/12/2011
01:29
Avatar
nolanlove
New Member
Members
Forum Posts: 1
Member Since:
09/12/2011
sp_UserOfflineSmall Offline

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

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

Currently Online:
35 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