1. #1
    Sencha User
    Join Date
    Nov 2012
    Posts
    14
    Answers
    1
    Vote Rating
    0
    travelbug is on a distinguished road

      0  

    Default Answered: How to sort case-insensitive when using addSortInfo

    Answered: How to sort case-insensitive when using addSortInfo


    I would like to sort my treestore so I tried the following. The problem was it sorted case-sensitive so how can I sort it case-insensitive?

    store.addSortInfo(new StoreSortInfo<BaseDto>(props.name(), SortDir.ASC));

  2. The default uses the standard Comparable.compareTo sort, which for String (your property is a String) is case sensitive. StoreSortInfo has other constructors, including one that takes a Comparator, allowing you to specify how you want the sort to be performed:

    Code:
    store.addSortInfo(new StoreSortInfo<BaseDto>(props.name(), new CaseInsensitiveComparator(),  SortDir.ASC))
    
    //...
    public class CaseInsensitiveComparator implements Comparator<String>() {
      public int compare(String o1, String o2) {
        //implement logic here - here's what it could look like:
        return o1.toLowerCase().compareTo(o2.toLowerCase());
      }
    }

  3. #2
    Sencha - GXT Dev Team
    Join Date
    Feb 2009
    Location
    Minnesota
    Posts
    2,731
    Answers
    109
    Vote Rating
    90
    Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light

      0  

    Default


    The default uses the standard Comparable.compareTo sort, which for String (your property is a String) is case sensitive. StoreSortInfo has other constructors, including one that takes a Comparator, allowing you to specify how you want the sort to be performed:

    Code:
    store.addSortInfo(new StoreSortInfo<BaseDto>(props.name(), new CaseInsensitiveComparator(),  SortDir.ASC))
    
    //...
    public class CaseInsensitiveComparator implements Comparator<String>() {
      public int compare(String o1, String o2) {
        //implement logic here - here's what it could look like:
        return o1.toLowerCase().compareTo(o2.toLowerCase());
      }
    }

  4. #3
    Sencha User
    Join Date
    Nov 2012
    Posts
    14
    Answers
    1
    Vote Rating
    0
    travelbug is on a distinguished road

      0  

    Default


    That worked nicely. Thank you!

  5. #4
    Sencha User
    Join Date
    Apr 2013
    Posts
    4
    Vote Rating
    0
    mpavlis is on a distinguished road

      0  

    Default Another way

    Another way


    I had the similiar issue and i'm new to sencha, I searched around fro a few hours and tried several things. Frustrated I decided just to change the Ext.Data.Proxy.SQL.JS file. I'm my opinion, I think all string comparision should be case insensative by default.

    Changes I made are in red.


    selectRecords: function(transaction, params, callback, scope) { var me = this, table = me.getTable(), idProperty = me.getModel().getIdProperty(), sql = 'SELECT * FROM ' + table, records = [],
    filterStatement = ' WHERE ',

    sortStatement = ' ORDER BY UPPER(',


    i, ln, data, result, count, rows, filter, sorter, property, value; result = new Ext.data.ResultSet({ records: records, success: true }); if (!Ext.isObject(params)) { sql += filterStatement + idProperty + ' = ' + params; } else { ln = params.filters && params.filters.length; if (ln) { for (i = 0; i < ln; i++) { filter = params.filters[i]; property = filter.getProperty(); value = filter.getValue(); if (property !== null) { sql += filterStatement + property + ' ' + (filter.getAnyMatch() ? ('LIKE \'%' + value + '%\'') : ('= \'' + value + '\'')); filterStatement = ' AND '; } } } ln = params.sorters && params.sorters.length; if (ln) { for (i = 0; i < ln; i++) { sorter = params.sorters[i]; property = sorter.getProperty(); if (property !== null) {

    sql += sortStatement + property + ') ' + sorter.getDirection();

    sortStatement = ', '; } } } // handle start, limit, sort, filter and group params if (params.page !== undefined) { sql += ' LIMIT ' + parseInt(params.start, 10) + ', ' + parseInt(params.limit, 10); } } transaction.executeSql(sql, null, function(transaction, resultSet) { rows = resultSet.rows; count = rows.length; for (i = 0, ln = count; i < ln; i++) { data = rows.item(i); records.push({ clientId: null, id: data[idProperty], data: data, node: data }); } result.setSuccess(true); result.setTotal(count); result.setCount(count); if (typeof callback == 'function') { callback.call(scope || me, result); } }, function(transaction, errors) { result.setSuccess(false); result.setTotal(0); result.setCount(0); if (typeof callback == 'function') { callback.call(scope || me, result); } } ); },
    Last edited by mpavlis; 2 May 2013 at 6:20 AM. Reason: The format was destroyed after save

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi