Search code examples
extjssencha-touch

how to filter data from store in extJS?


Please see bellow code, that I use for filtering data.

listeners: {
    keyup: function (e, t, eOpts) {
        var text = e.getValue();
        var s = Ext.getStore('TempSensorDetailsStore');
        s.clearFilter();
        if (text) {
            s.filterBy(function (rec) {
                var str = (rec.get('vehicleNo')).toLowerCase();
                var res = str.indexOf(text.toLowerCase());

                if (res == 0) {
                    return true;
                }
            });
        } else {
            s.clearFilter();
        }
    }
}

Above code get filter the data, But not as per my expectations,

Search Result showing record which is matching the first letter of vehicle Number only...it should return the vehicle No if that character is present in Vehicle no

For Example. Vehicle No.Abc-37046 and if user search 37046 then also it returns vehicle


Solution

  • I got Solution,

    There was just need to change code

     if (res >- 1) 
    

    Instead of

     if (res == 0)