Situation:
kendo DataSource
var ordersDataSource = new kendo.data.DataSource({ type: "odata", transport: { read: { url: "http://localhost/odata.svc/Orders?$expand=OrderDetails" } }, schema: { type: "json", data: function(response){ return response.value; } total: function(response){ return response['odata.count']; } }, serverPaging: true, serverFiltering: true, serverSorting: true })
the json data read from the odata source is like:
{ odata.metadata: "xxxx", odata.count: "5", value: [ { OrderId: 1, OrderedDate: "2013-02-20", OrderInfoA: "Info A", OrderInfoB: "Info B" OrderDetails: [ { OrderDetailId: 6, OrderDetailInfoC: "Info C", OrderDetailInfoD: "Info D" }, { //Another OrderDetail's data } ] }, { // Another Order's data } ] }
Question 1:
1.If I wanna define a "computed" property: OrderedDateRelative, which should be the number of days between Today(2013-02-25) and the Day the Order was Created(2013-02-20), Like: "5 days ago", HOW can i achieve this in the client side?
Answer to Question1: http://jsbin.com/ojomul/7/edit
Question 2 --UPDATE--
2.Every Order has its Nested Property OrderDetails, so is it possible to define a Calculated Field for the Nested OrderDetails Property? Like: OrderDetailInfoCAndD for each OrderDetail, and the value should be something like: OrderDetailInfoC + OrderDetailInfoD, which is "Info C Info D"?
Thanks,
dean
You can create a calculated field by specifying the model of the data source:
Here is a live demo: http://jsbin.com/ojomul/1/edit
Here is a way to use calculated field in Kendo Grid.
Below an example to use it in a grid. It can then also sort the column.