Alan Mosley
Top achievements
Rank 1
Alan Mosley
asked on 16 Sep 2014, 12:36 PM
I am trying to get autocomplete to filter, with no luck using webapi 2 and odata 4
when i look at the url decoded i see
but looking at webapi odata doc filtering syntax looks different, see
for example the syntax for conatins is
am I missing something?
Thanks
when i look at the url decoded i see
/odata/Locations?filter[logic]=and&filter[filters][0][value]=mun&filter[filters][0][operator]=contains&filter[filters][0][field]=Name&filter[filters][0][ignoreCase]=true
but looking at webapi odata doc filtering syntax looks different, see
for example the syntax for conatins is
$filter=substringof('zz',Name)
am I missing something?
Thanks
10 Answers, 1 is accepted
0
Hello Alan,
Have you set the autocomplete dataSource type to odata? The parameters will not be formatted if the type is not set.
Also, I am not sure if I understand which OData version you are using because the link that your provided describes how to use OData 3. Could you clarify? The dataSource currently supports only version 2. Adding support for OData 4 is planned for the next release. It is possible to override the built-in functions to add support for server filtering with OData 3 or 4 but the needed changes will depend on the version.
Regards,
Daniel
Telerik
Have you set the autocomplete dataSource type to odata? The parameters will not be formatted if the type is not set.
Also, I am not sure if I understand which OData version you are using because the link that your provided describes how to use OData 3. Could you clarify? The dataSource currently supports only version 2. Adding support for OData 4 is planned for the next release. It is possible to override the built-in functions to add support for server filtering with OData 3 or 4 but the needed changes will depend on the version.
Regards,
Daniel
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Alan Mosley
Top achievements
Rank 1
answered on 18 Sep 2014, 10:23 AM
Thanks, I have tried version 3 and 4.
I have made a hack to get the value out of the request, this was not too hard as I only need the one value.
When do you think we will have the update for oData4.
Do you have any examples of overriding methods for version 4?
Thanks
I have made a hack to get the value out of the request, this was not too hard as I only need the one value.
When do you think we will have the update for oData4.
Do you have any examples of overriding methods for version 4?
Thanks
0
Hello again Alan,
The next official release is expected in November.
As for overriding the methods - for version 3 it should be sufficient to override the schema data and total functions:
and set the request dataType to "json".
For OData 4 you should also override the transport parameterMap function and replace $inlinecount with $count and substringof with contains:
Regards,
Daniel
Telerik
The next official release is expected in November.
As for overriding the methods - for version 3 it should be sufficient to override the schema data and total functions:
schema: {
data:
function
(data) {
return
data.value;
},
total:
function
(data) {
return
data[
"@odata.count"
];
}
}
For OData 4 you should also override the transport parameterMap function and replace $inlinecount with $count and substringof with contains:
parameterMap:
function
(options) {
var
result = kendo.data.transports.odata.parameterMap(options);
if
(result.$filter) {
result.$filter = result.$filter.replace(/substringof\(
'(\w+)'
,(\w+)\)/g,
"contains($2, '$1')"
);
}
delete
result.$inlinecount;
result.$count =
true
;
return
result;
}
Regards,
Daniel
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Alan Mosley
Top achievements
Rank 1
answered on 22 Sep 2014, 06:14 PM
Thanks, I tried the code but had no affect.
but looking at the code, is it the wrong way around?
shouldn't we be replacing with substingof, rather then be searching for substringof?
This is what autocomplete is sending
http://localhost:54761/odata/oLocationViews?filter[logic]=and&filter[filters][0][value]=xxxxxx&filter[filters][0][operator]=contains&filter[filters][0][field]=FormatedLocation&filter[filters][0][ignoreCase]=true
this is what I need
$filter=substringof('xxxx',Name)
I am not good enough with regex to get it to work.
Thanks
but looking at the code, is it the wrong way around?
shouldn't we be replacing with substingof, rather then be searching for substringof?
This is what autocomplete is sending
http://localhost:54761/odata/oLocationViews?filter[logic]=and&filter[filters][0][value]=xxxxxx&filter[filters][0][operator]=contains&filter[filters][0][field]=FormatedLocation&filter[filters][0][ignoreCase]=true
this is what I need
$filter=substringof('xxxx',Name)
I am not good enough with regex to get it to work.
Thanks
0
Hi Alan,
Could you provide the code that you are currently using? From the provided URL it seems that the parameters are still not formatted with the odata transport.
As for the substringof operator - in version 4 it was changed to contains:
http://docs.oasis-open.org/odata/new-in-odata/v4.0/cn01/new-in-odata-v4.0-cn01.html
Regards,
Daniel
Telerik
Could you provide the code that you are currently using? From the provided URL it seems that the parameters are still not formatted with the odata transport.
As for the substringof operator - in version 4 it was changed to contains:
http://docs.oasis-open.org/odata/new-in-odata/v4.0/cn01/new-in-odata-v4.0-cn01.html
Regards,
Daniel
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Alan Mosley
Top achievements
Rank 1
answered on 24 Sep 2014, 12:47 AM
My code thanks
​$(document).ready(function () {
var dataSource = new kendo.data.DataSource({
dataType: "json",
serverFiltering: true,
transport: {
read: "/odata/oLocationViews"
},
schema: {
data: function (data) {
console.log(data.value);
return data.value;
}
}
});
$("#locations").kendoAutoComplete({
dataTextField: "FormatedLocation",
filter: "contains",
minLength: 3,
type: "odata",
dataSource: dataSource,
select: LocationIdObject.locationIdOnSelect,
parameterMap: function (options, type) {
var paramMap = kendo.data.transports.odata.parameterMap(options);
delete paramMap.$inlinecount;
delete paramMap.$format;
return paramMap;
}
});
});
​$(document).ready(function () {
var dataSource = new kendo.data.DataSource({
dataType: "json",
serverFiltering: true,
transport: {
read: "/odata/oLocationViews"
},
schema: {
data: function (data) {
console.log(data.value);
return data.value;
}
}
});
$("#locations").kendoAutoComplete({
dataTextField: "FormatedLocation",
filter: "contains",
minLength: 3,
type: "odata",
dataSource: dataSource,
select: LocationIdObject.locationIdOnSelect,
parameterMap: function (options, type) {
var paramMap = kendo.data.transports.odata.parameterMap(options);
delete paramMap.$inlinecount;
delete paramMap.$format;
return paramMap;
}
});
});
0
Alan Mosley
Top achievements
Rank 1
answered on 24 Sep 2014, 01:42 AM
sorry to makes thing clear,
I have tried changing datatype from odata to json on both datasouce and autocomplete.
I have also changed api to use odata 3, using nugget package odata for webapi 2.2 v1 to 3
still cant get it to work
I have tried changing datatype from odata to json on both datasouce and autocomplete.
I have also changed api to use odata 3, using nugget package odata for webapi 2.2 v1 to 3
still cant get it to work
0
Hello Alan,
There are a few configuration issues in the code that you provided:
Regards,
Daniel
Telerik
There are a few configuration issues in the code that you provided:
- the parameterMap function should be set to the transport and not the grid.
- the type should be set to the dataSource and not the grid.
- the dataType should be set to the request options and not the dataSource
var
dataSource =
new
kendo.data.DataSource({
type:
"odata"
,
serverFiltering:
true
,
transport: {
read: {
url:
"/odata/oLocationViews"
,
dataType:
"json"
,
},
parameterMap:
function
(options, type) {
var
paramMap = kendo.data.transports.odata.parameterMap(options);
delete
paramMap.$inlinecount;
delete
paramMap.$format;
return
paramMap;
}
},
schema: {
data:
function
(data) {
console.log(data.value);
return
data.value;
}
}
});
$(
"#locations"
).kendoAutoComplete({
dataTextField:
"FormatedLocation"
,
filter:
"contains"
,
minLength: 3,
dataSource: dataSource,
select: LocationIdObject.locationIdOnSelect
});
Regards,
Daniel
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Alan Mosley
Top achievements
Rank 1
answered on 25 Sep 2014, 04:24 AM
Thanks
I had moved things around a lot trying to get things working, after reading many things on internet.
I have working now.
I did have to add
as well as serverfiltering
That got things working but very slow, I had been reading the below article that stats to return an IQueryable, but changing to IEnumerable got working fast.
Thanks for your help once again
I had moved things around a lot trying to get things working, after reading many things on internet.
I have working now.
I did have to add
total: function (data) {
return data.length;
}
as well as serverfiltering
That got things working but very slow, I had been reading the below article that stats to return an IQueryable, but changing to IEnumerable got working fast.
Thanks for your help once again
0
Alan Mosley
Top achievements
Rank 1
answered on 25 Sep 2014, 04:24 AM
Sorry for got link to article
http://blogs.telerik.com/kendoui/posts/12-10-25/using_kendo_ui_with_mvc4_webapi_odata_and_ef
http://blogs.telerik.com/kendoui/posts/12-10-25/using_kendo_ui_with_mvc4_webapi_odata_and_ef