alphabetSearch bug with mixed case

alphabetSearch bug with mixed case

barbequesaucebarbequesauce Posts: 4Questions: 2Answers: 0

Hi -

I have alphabetSearch working nicely in a table. Recently data was added to the table with mixed case - specifically, lowercase i as the first letter of the word.

I was able to add [a-zA-Z] to get it to bin correctly, but I can't see why it doesn't return the lowercase row. Any thoughts?

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,166Questions: 26Answers: 4,921

    I'm guessing you are referring to the Alphabet Search blog. I changed the code for lower case only and have ashton Cox with lower case. I also commented out the .toUpperCase(); in the bin function:

        for ( var i=0, ien=data.length ; i<ien ; i++ ) {
            letter = data[i].charAt(0)  //.toUpperCase();
    .....
    

    http://live.datatables.net/zukuwiwi/1/edit

    Not sure what changes you made. Maybe you can post a test case or update mine to show what you have. Then we can help you debug.

    Kevin

  • kthorngrenkthorngren Posts: 21,166Questions: 26Answers: 4,921

    Updated my example to have both upper and lower case search letters and it still works:
    http://live.datatables.net/zukuwiwi/2/edit

    Kevin

  • barbequesaucebarbequesauce Posts: 4Questions: 2Answers: 0

    Thanks. It was the blog I was referring to.

    The second example is closer to my goal; any thoughts on how to combine the upper- and lower-case in the search? Meaning, clicking on A would result in both Angelica & ashton in the result set?

  • kthorngrenkthorngren Posts: 21,166Questions: 26Answers: 4,921
    Answer ✓

    Put back the .toUpperCase(); that I commented out above so that the count under the letters is correct. Then add the .toUpperCase(); to the searchData in the search plugin, for example:

        if ( searchData[0].charAt(0).toUpperCase() === context.alphabetSearch ) {
            return true;
        }
    

    Here is the updated example:
    http://live.datatables.net/zukuwiwi/5/edit

    Kevin

  • barbequesaucebarbequesauce Posts: 4Questions: 2Answers: 0

    Thank you!

This discussion has been closed.