This is a migrated thread and some comments may be shown as answers.

Grid string filter producing incorrect results

2 Answers 109 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Brian
Top achievements
Rank 1
Brian asked on 11 Dec 2012, 05:12 PM
So I've dug all through this trying to figure out what is wrong with the filtering and I can't seem to figure it out. Basically my issue is using the "Ends with" filter on a string type. I have been able to reproduce a sample of this and put it on JSFiddle:

Click to view demo

If you filter on the Name column, select "Ends with" and the text "Smith" you get the people named: Joe Smith, Ryan, and Slappy Smith. How or why Ryan got in there is baffling to me...as he clearly shouldn't be.

I stepped through a good portion of the open source and found that this is what's happening:
(d.Name.toLowerCase().lastIndexOf('smith') == d.Name.toLowerCase().length - 5)

I'm assuming this has something to do with the way the data is being cached/queried but I have been unable to find a solution. At first I thought it may be because "Ryan" is shorter than the string I'm searching for, but in that case Don and Bob should have showed up as well...

Any thoughts/explanations/solutions?

2 Answers, 1 is accepted

Sort by
0
Marcin Butlak
Top achievements
Rank 2
answered on 11 Dec 2012, 10:49 PM
d.Name.toLowerCase().lastIndexOf('smith') == d.Name.toLowerCase().length - 5
The statement isn't foolproof because "Ryan" is 4 letter long and obviously has no substring "smith" so the first part:
d.Name.toLowerCase().lastIndexOf('smith')
Return -1 and the second part also returns -1 which is true in the condition but not correct...
This is how it should look:
var index  = d.Name.toLowerCase().lastIndexOf('smith');
 
if (index > -1 && index == d.Name.toLowerCase().length - 5) {
 
}
So there is a bug in the filter script and should be corrected by the kendoui team.
0
Accepted
Nikolay Rusev
Telerik team
answered on 12 Dec 2012, 09:20 AM
Hello guys,

The version in the jsfiddle is a bit old. Indeed there was such issue which is fixed in more recent releases. You can see updated example with latest official release:
http://jsfiddle.net/xKPgX/2/

Regards,
Nikolay Rusev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
Brian
Top achievements
Rank 1
Answers by
Marcin Butlak
Top achievements
Rank 2
Nikolay Rusev
Telerik team
Share this question
or