This is a migrated thread and some comments may be shown as answers.

Autocomplete with odata v4

8 Answers 250 Views
AutoComplete
This is a migrated thread and some comments may be shown as answers.
matt
Top achievements
Rank 1
matt asked on 03 Mar 2015, 03:14 PM
Does the Autocomplete widget support odata v4 in the same way that the grid does?

I'm finding that
substringof(xxx
is being sent to the server instead of contains.

I am using odata-v4 in a grid and it seems to work fine.

But I've got this in the parameterMap override.
pmap.$filter = pmap.$filter.replace(/substringof\((.+),tolower\((.*?)\)\)/, "contains(tolower($2),tolower($1))");

which is a bit nasty!

snippet of my autocomplete settings..
filter: "contains",
            minLength: minLength || 3,
            placeholder: placeholder,
            dataSource: {
                type: "odata-v4",
                serverFiltering: true,
                transport: {
                    read: {
                        type: "GET",
                        dataType: "json",
                        url: "--some url--"
                    },
                    parameterMap: function(model) {
                         var pmap = kendo.data.transports.odata.parameterMap(model);
                         if (pmap.$filter) {
                               pmap.$filter = pmap.$filter.replace(/substringof\((.+),tolower\((.*?)\)\)/, "contains(tolower($2),tolower($1))");
                         }
                         return pmap;
                    }
                },

Can't help but think I'm missing something

8 Answers, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 05 Mar 2015, 10:02 AM
Hello,

I prepared a simple MVC demo that shows how to bind the autocomplete to ODATA v4. The demo is based on the Grid's "how-to" demo available in Github.

Regards,
Georgi Krustev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
matt
Top achievements
Rank 1
answered on 05 Mar 2015, 10:50 AM
Hi,
Thanks, yes, I have seen that demo previously.  I am not however using the MVC extensions, although I appreciate that shouldn't make any difference, it seems too with the AutoComplete.

I have set type="odata-v4" in the js and it works fine for grids.

But in the auto complete it does not.  You can see in the snippet above what I am using and even trying to alter it in the parameterMap, but that doesn't seem to work either.  But it still doesn't work with odata-v4.
0
Accepted
Georgi Krustev
Telerik team
answered on 05 Mar 2015, 11:49 AM
Hello SharpLogic,

The attached archive demo (not the linked one) shows an AutoComplete widget initialized with JavaScript. The widget binds as expected to the ODATA service:
<script>
    $(function () {
        $("#autocomplete").kendoAutoComplete({
            dataTextField: "ProductName",
            dataSource: {
                type: "odata-v4",
                transport: {
                    read: { "url": "/odata/Products" }
                },
                serverFiltering: true
            }
        });
    });
</script>
Could you let me know what is different between this demo and your application.

Regards,
Georgi Krustev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
matt
Top achievements
Rank 1
answered on 06 Mar 2015, 11:59 AM
Hey Georgi

As you can see my snippet above is pretty much the same...I've not touched it for a couple of weeks, it's not been working, the client picked up on it.
Yet today...it appears to be working!!

I've not changed anything!! Honest!!!

0
matt
Top achievements
Rank 1
answered on 18 Mar 2015, 11:59 AM
I know this is marked as Answered, but i'm still experiencing strange behaviour with odata-v4.

So if I were to override the parameterMap on the datasource for whatever reason this basically goes back to odata original? It seems your solution for odata-v4 is to override the parameterMap and tweak the request?

My problem comes as whilst I can now execute odata-v4 contains commands etc.  With odata-v4 they are not case insensitive like they were with substringof etc etc.  Let face it, no user wants a case sensitive search.

Thx

0
Georgi Krustev
Telerik team
answered on 20 Mar 2015, 09:42 AM
Hello Steve,

In general, the data source with ODATA v4 type performs case-insensitive filter requests. Check this screencast (http://screencast.com/t/uOkqNibm) that shows how the filter value is lowered using both "startswith" and "contains" filters.

Regards,
Georgi Krustev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
matt
Top achievements
Rank 1
answered on 20 Mar 2015, 10:21 AM
Hi Georgi,

In general?  What does that mean?

I can confirm that when set as "contains" in an auto-complete widget the search is case insensitive when using odata-v4.

However for a grid filter the behaviour is different.

See the attached screen shot of trying to filter on the grid, the network call and code snippet.  

The only way I've got around this is to create a parameterMap override.  When I do this, I notice that even though I am specifying "odata-v4" the filter actually comes into the override function as "substringof" not "contains".
 


0
Georgi Krustev
Telerik team
answered on 24 Mar 2015, 08:07 AM
Hello Steve,

The ODATA v4 data source type will use a case-insensitive filtration if contains or startswith operators are used. When "equal" operator is used then the comparison will be case-sensitive. This behavior is enabled if the filter descriptor has "ignoreCase: true", which Grid does not set.

What I would suggest you is to use a custom parameterMap function, modify the filter adding "ignoreCase: true" and stringify the options using built-in odata-v4 parameter map:
return kendo.data.transports["odata-v4"].parameterMap.call(this, data, type);

Regards,
Georgi Krustev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
AutoComplete
Asked by
matt
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
matt
Top achievements
Rank 1
Share this question
or