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