Like if this is the text in the DB
"This is the string I want to find"
In the autocomplete I want to type
"string find" (without the quotes obviously)
Doable somehow?? I have it set to a contains filter already...
11 Answers, 1 is accepted
The required functionality is a custom filtering, which should be performened on the server. You can turn on the serverFiltering to "true" and perform the custom filtering on the server and return the correctly filtered data.
Georgi Krustev
the Telerik team
So this is what you do now:
$filter=substringof('wheat bread',AliasDesc)
This is what I want it to do though:
$filter=substringof('wheat',AliasDesc) and substringof('bread',AliasDesc)
I would expect it to search for "wheat bread" if I enclose it in quotes
Could you not add a new search "Type" which treats every word in the string as a new "substringof"? So not just starts, ends, contains?
Thank you for the feature request. If more users vote for it in the user-voice opened on the same matter we will schedule it for further investigation.
Regards,
the Telerik team
Has it even been discussed though georgi?...
For anyone reading this post, this is the uservoice link
http://kendo.uservoice.com/forums/127393-kendo-ui-feedback/suggestions/2464433-google-like-odata-autocomplete
I confirm that this has been discussed internally. We decided to let the users vote for this feature request to determine what the demand is. This is how we handle all feature requests which are not trivial to implement.
Please have in mind that the feature set for the upcoming release has already been determined.
Atanas Korchev
the Telerik team
I did what you suggested and made a custom filter method on the service
(fiddler this)
http://odata.gourmetsleuth.com/USDA.svc/FoodSearch?$format=json&searchterm='wheat%20germ'&take=10
However I'm a bit stumped how to convert the custom method to the KendoDS format
This is what I have so far (and it calls back, but the combo doesn't open)
_autoCompleteDS =
new
kendo.data.DataSource({
type:
"jsonp"
,
//Specifies data protocol
pageSize: 10,
//Limits result set
severFiltering:
false
,
serverPaging:
false
,
transport: {
read: {
url:
"http://odata.gourmetsleuth.com/USDA.svc/FoodSearch?$format=json&$callback=callback&searchterm='wheat%20germ'"
,
dataType:
'jsonp'
,
cache:
true
,
jsonp:
false
,
jsonpCallback:
'callback'
}
}
});
Seems that the DS configured to oData in my working version returns data.d.results, where this custom method returns data.d
So there's two problems
1) Unsure of proper structure
2) Unsure how to get the searched term from the combo into the "searchterm" var for the service.
Your method seems to return OData v1 whereas the Kendo DataSource needs OData v2. You can find more info in the OData JSON specification.
You can use the data setting of the transport to send additional parameters:transport: {
read: {
data: function() {
return {
searchterm: $("#autocomplete").data("kendoAutoComplete").value()
}
}
}
}
All the best,
Atanas Korchev
the Telerik team
config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
So I assume then I need to decorate the method perhaps with something or return it in that format manually...I'll figure it out, thanks
1) There doesn't appear to be anything to decorate my service operation method with to have it return wrapped with V2, so I'm trying to do it as JSONP instead of type "odata"
_autoCompleteDS =
new
kendo.data.DataSource({
type:
"jsonp"
,
//Specifies data protocol
pageSize: 10,
//Limits result set
severFiltering:
true
,
serverPaging:
true
,
transport: {
read: {
url:
"http://odata.gourmetsleuth.com/USDA.svc/FoodSearch?$format=json&$callback=callback"
,
dataType:
'jsonp'
,
cache:
true
,
jsonp:
false
,
jsonpCallback:
'callback'
,
data:
function
() {
return
{
searchterm: $(
"#food-box"
).data(
"kendoComboBox"
).text()
}
}
}
}
});
2) oData requires the string params to be wrapped in single quotes
data:
function
() {
return
{
searchterm:
"'"
+ $(
"#food-box"
).data(
"kendoComboBox"
).text() +
"'"
}
}
However doing that seems to force the DS to go insane and refresh itself over and over and over again (really fast)...cached...but still
I created an example showing how to implement filtering using OData (without relying on the built-in OData support). You can find it here.
It turns out that jQuery will encode special symbols provided by the data setting of the transport (such as $ in $filter). I used parameterMap instead which is not mangled by jQuery.I hope this helps,
Atanas Korchev
the Telerik team
http://jsfiddle.net/b4qre/10/