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. Image for the cookie policy date

OData v4 Generated query variant

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?



6 Replies

AS Alan Sangeeth S Syncfusion Team April 8, 2016 07:02 AM UTC

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



WO Wouter April 8, 2016 09:37 AM UTC

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


WO Wouter April 8, 2016 10:24 AM UTC

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


GV Gowthami V Syncfusion Team April 11, 2016 12:59 PM UTC

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.


WO Wouter April 12, 2016 07:12 AM UTC

Great! Thanks.


GV Gowthami V Syncfusion Team April 13, 2016 12:09 PM UTC

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

Loader.
Up arrow icon