We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

OData v4 Generated query variant

Thread ID:

Created:

Updated:

Platform:

Replies:

123647 Apr 6,2016 08:56 AM Apr 13,2016 08:09 AM JavaScript 6
loading
Tags: ejDataManager
Wouter
Asked On April 6, 2016 08:56 AM

If I do this:

var dm = ej.DataManager({ url: "http://localhost:65055/odata/myApi", adaptor: new ej.ODataV4Adaptor() });
        $("#Grid").ejGrid({
            dataSource: dm,           
            columns: [
                         { field: "Created", format: "{0: dd/MM/yyyy HH:mm}", type: "date" },
                         { field: "Item.Title", headerText: "Title" },
                         { field: "Status" }
            ]
        });

The following query is generated correctly: http://localhost:65055/odata/myApi/?$expand=Item&$count=true&$skip=0&$top=6


But if I do this:

var dm = ej.DataManager({ url: "http://localhost:65055/odata/myApi", adaptor: new ej.ODataV4Adaptor() });
        $("#Grid").ejGrid({
            dataSource: dm,           
            columns: [
                         { field: "Created", format: "{0: dd/MM/yyyy HH:mm}", type: "date" },
                         { field: "Item.Title", headerText: "Title" },
                         { field: "Status" },
                         { field: "Item.LinkingCollection.0.LinkedItem.PropertyOne", headerText: "One" }
            ]
        });

Then the query looks like this http://localhost:65055/odata/myApi/?$expand=Item,Item/LinkingCollection,Item/LinkingCollection/0,Item/LinkingCollection/0/LinkedItem&$count=true&$skip=0&$top=6 and gives an error

It works (and queries more efficient) if the ejQuery is customized and the url is: http://localhost:65055/odata/myApi/?$expand=Item($select=Title;$expand=LinkingCollection($select=LinkedItem;$expand=LinkedItem($select=PropertyOne)))&$select=Created,Item,Status&$count=true&$skip=0&$top=6

The query is editable via the ejQuery option to give the correct results, but the column options cause the url to be populated with the slashes. Is there a way to prevent that? Or is the query generation configurable?



Alan Sangeeth S [Syncfusion]
Replied On April 8, 2016 03:02 AM

Hi Wouter,

 

Thanks for using Syncfusion Products.


We have provided in-built support for Complex binding of Grid datasource. For binding “collection of complex data” we achieved it through a workaround where have used custom adaptor for Grid datasource.

 

In the custom adaptor, we have extended the ODataV4Adaptor and overridden processQuery method to manipulate the expand query. Please refer the following code example.

var adaptor = new ej.ODataV4Adaptor().extend({       

        processQuery: function (ds, query) {

            for (var i = query._expands.length - 1; i >= 0 ; i--) {

                if (query._expands[i].indexOf("/0") != -1) {

                    if (query._expands[i].indexOf("/0/") != -1) {

                        query._expands[i] = query._expands[i].replace("/0/", "($expand=") + ")";

                    }

                    else

                        query._expands.splice(i, 1);

                }

            }

            return this.base.processQuery.apply(this, [ds, query]);

        },

 

    });

 

var dm = ej.DataManager({ url: "http://services.odata.org/V4/Northwind/Northwind.svc/Customers", adaptor: new adaptor(), crossDomain: true });

 

$("#FlatGrid").ejGrid({

            dataSource: dm,

})

 

For your convenience we have created a sample in JSPlayground and please find the sample link below

http://jsplayground.syncfusion.com/1j0zce0y

 

For more information in custom adaptors, please refer the following link.

http://help.syncfusion.com/js/datamanager/data-adaptors#custom-adaptor

http://help.syncfusion.com/js/grid/data-binding#other-restful-web-services

 

Regards,

Alan Sangeeth S


Wouter
Replied On April 8, 2016 05:37 AM

Thanks for the example. I adapted it for my scenario because it didnt work right away.

Here is mine: http://jsplayground.syncfusion.com/rtfdx1r2

Works for a ASP.NET 5 Web Api ODataController from Microsoft.AspNet.OData.5.9.0

Wouter
Replied On April 8, 2016 06:24 AM

I do see now that filtering/searching is broken wit a custom adapter. Is that by design?

Gowthami V [Syncfusion]
Replied On April 11, 2016 08:59 AM

Hi Wouter,

We have analyzed your query and we found that while externally modifying the query using Custom Adaptor concept it overwrites the filtering and sorting behavior. So that only filtering and sorting is not working while  using the provided workaround solution.

We have a support for ODataV4Adaptor for complex data binding. But for complex array data binding, we considered this “Need to provide support for Complex array data bind for ODataV4Adaptor ” as a usability issue and a support incident has been created under your account to track the status of this requirement. Please log on to our support website to check for further updates.

https://www.syncfusion.com/account/login?ReturnUrl=/support/directtrac/incidents

Regards,

Gowthami V.

Wouter
Replied On April 12, 2016 03:12 AM

Great! Thanks.

Gowthami V [Syncfusion]
Replied On April 13, 2016 08:09 AM

Hi Wouter,
 
Thanks for your update.
 
Get back to us if you need further assistance.
 
Regards,
 
Gowthami V.

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;