Grid string filter producing incorrect results

3 posts, 1 answers
  1. Brian
    Brian avatar
    17 posts
    Member since:
    Nov 2012

    Posted 11 Dec 2012 Link to this post

    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 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. Marcin Butlak
    Marcin Butlak avatar
    26 posts
    Member since:
    Dec 2012

    Posted 11 Dec 2012 Link to this post

    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:
    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.
  3. Answer
    Nikolay Rusev
    Nikolay Rusev avatar
    2287 posts

    Posted 12 Dec 2012 Link to this post

    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:

    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!
Back to Top