PDA

View Full Version : case insensitive store.findExact()



raj_plays
6 Sep 2010, 2:48 AM
Hi,
Is there a case insensitive version of store.findExact()?

Condor
6 Sep 2010, 2:55 AM
No, there isn't. You'll have to use findBy with your own comparator.

raj_plays
6 Sep 2010, 5:58 AM
Is this the way to go about it?


if(store.findBy(compareCaseInsensitive.createDelegate(this, [column, value], true), this, 1) != -1)
return false;

......

function compareCaseInsensitive(record, id, column, value)
{
if(record.get(column).toLowerCase() == value.toLowerCase())
return true;
else
return false;
}

Condor
6 Sep 2010, 6:05 AM
More efficient:

function compareCaseInsensitiveFn(column, value) {
var re = new RegExp('^' + value + '$', 'i');
return function(rec) {
return re.test(rec.get(column));
}
}

function containsCaseInsensitive(store, column, value) {
return store.findBy(compareCaseInsensitiveFn(column, value)) >= 0;
}

raj_plays
6 Sep 2010, 11:10 AM
Thank you, Condor!

4 Dec 2013, 8:01 AM
Hi Condor,

My name is Karan and I am very new to extjs. I need a liitle help in understanding your solution.

You suggested :-


Code:
function compareCaseInsensitiveFn(column, value) {
var re = new RegExp('^' + value + '$', 'i');
return function(rec) {
return re.test(rec.get(column));
}
}

function containsCaseInsensitive(store, column, value) {
return store.findBy(compareCaseInsensitiveFn(column, value)) >= 0;
}

I tried this solution and it worked perfectly fine for me. But after that I tried the below one (which is same as your code but with a little modification to "compareCaseInsensitiveFn") :-


Code:
function compareCaseInsensitiveFn(column, value) {
var re = new RegExp('^' + value + '$', 'i');

return re.test(rec.get(column));

}

function containsCaseInsensitive(store, column, value) {
return store.findBy(compareCaseInsensitiveFn(column, value)) >= 0;
}

This code did not run and threw an error. Can you please explain this to me?

PS :- Sorry about the formatting, I saw in preview, it looks really bad but again, I am new to Sencha also, do not know how to make it look good.

raj_plays
6 Dec 2013, 5:47 AM
store.findBy takes a function as the first arg and you are trying to pass a boolean.

Also, to format code use the Code tags by clicking the # in the menu above.