var oFilter = new Filter(
"tolower(LastName)",
FilterOperator.Contains,
"'" + filterString.toLowerCase().replace("'","''") + "'"
);
When we use a search string like "O'donnell" this translates into:
$filter=substringof(%27o%27%27donnell%27, tolower(FirstName))
As per OData specification the text we search in can be lowered using tolower():
tolower(FirstName)
The searched text has to be lowered as well using the javascript function toLowerCase(). In addition it is surrounded by quotes to ensure it is a string when added to the odata filter. And finally to avoid problems if the search string contains quotes we have to escape them by replacing with two quotes.
Happy coding!