<script type="text/javascript">
$(function () {
var dataManager = ej.DataManager({ url: "http://services.odata.org/V4/Northwind/Northwind.svc/", crossDomain: true, adaptor: new customAdaptor() });
var query = new ej.Query().from("Orders").select("OrderID", "CustomerID", "EmployeeID").take(5);
var promise = dataManager.executeQuery(query);
promise.done(function (e) {
$("#table1 tbody").html($("#tableTemplate").render(e.result.value));
});
});
// extending ODataAdaptor as custom adaptor to alter query creation based on our requirement
var customAdaptor = new ej.ODataAdaptor().extend({
convertToQueryString: function (req, query, dm) {
var res = [], tableName = req.table || "";
delete req.table;
if (dm.dataSource.requiresFormat)
req["$format"] = "json";
for (var prop in req)
res.push(prop + "=" + req[prop]);
res = res.join("&");
if (dm.dataSource.url && dm.dataSource.url.indexOf("?") !== -1 && !tableName)
return res;
return res.length ? tableName + "/?" + res : tableName || "";// add "/" or enclose the query string in '' single quotes
},
});
</script> |