Autocomplete with odata v4

9 posts, 1 answers
  1. SharpLogic
    SharpLogic avatar
    15 posts
    Member since:
    Feb 2014

    Posted 03 Mar 2015 Link to this post

    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
  2. Georgi Krustev
    Admin
    Georgi Krustev avatar
    3707 posts

    Posted 05 Mar 2015 Link to this post

    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!
     
  3. Kendo UI is VS 2017 Ready
  4. SharpLogic
    SharpLogic avatar
    15 posts
    Member since:
    Feb 2014

    Posted 05 Mar 2015 in reply to Georgi Krustev Link to this post

    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.
  5. Answer
    Georgi Krustev
    Admin
    Georgi Krustev avatar
    3707 posts

    Posted 05 Mar 2015 Link to this post

    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!
     
  6. SharpLogic
    SharpLogic avatar
    15 posts
    Member since:
    Feb 2014

    Posted 06 Mar 2015 in reply to Georgi Krustev Link to this post

    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!!!

  7. SharpLogic
    SharpLogic avatar
    15 posts
    Member since:
    Feb 2014

    Posted 18 Mar 2015 in reply to Georgi Krustev Link to this post

    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

  8. Georgi Krustev
    Admin
    Georgi Krustev avatar
    3707 posts

    Posted 20 Mar 2015 Link to this post

    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!
     
  9. SharpLogic
    SharpLogic avatar
    15 posts
    Member since:
    Feb 2014

    Posted 20 Mar 2015 in reply to Georgi Krustev Link to this post

    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".
     


  10. Georgi Krustev
    Admin
    Georgi Krustev avatar
    3707 posts

    Posted 24 Mar 2015 Link to this post

    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!
     
Back to Top
Kendo UI is VS 2017 Ready