This is a migrated thread and some comments may be shown as answers.

how do observablearray dataItem add property

3 Answers 80 Views
MVVM
This is a migrated thread and some comments may be shown as answers.
Jason
Top achievements
Rank 1
Jason asked on 23 Mar 2014, 03:57 PM
Dear Sir

I have a observablearray from a children property of remote service, which is a purchase order. You could image it as master-child structure.

after get observablearray of order details, I bind it to a grid. It works well.

But when I try to add a dependency property to this observablearray to calcuate ( quantity * unit price.) But it couldn't work.

 I know it could be done by bind "change" event and it works well. But I wonder if it can be done by dependency property or method.

there is the sample: http://jsfiddle.net/R6KSs/2/

Thank you very much.

Jason

3 Answers, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 24 Mar 2014, 02:13 PM
Hi Jason,

In your case the easiest solution is to use a template to calculate the "Amount" value.
{
   title: "Amount",
   template: "#: Qty * UnitPrice #"
},

For your convenience I updated your sample: http://jsfiddle.net/R6KSs/4/
Also please note that it is not needed to wrap the data array as Observable. The DataSource will automatically do that.

Regards,
Alexander Valchev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Jason
Top achievements
Rank 1
answered on 25 Mar 2014, 04:38 PM
Dear Alexander

thank you for your kind help. But
1. it will miss the format defined on "format" property.
2. when add new, it will be error on "qty" isn't defined. 
3. I still need to work on the change event because there is a sum property on the master which be = sum ( the detail's amount.)

Frankly, there will be more complex logic needs to get help with dependency property, like complex conditional format the row, cell or column. 

is there any way to create a method or property into it?

Thank you very much.

Jason

0
Alexander Valchev
Telerik team
answered on 27 Mar 2014, 12:59 PM
Hello Jason,

In case you insist using computed fields please follow the approach described here.
For your convenience I updated your sample (and Kendo UI version it is using): http://jsbin.com/pehakaca/2/edit

Regards,
Alexander Valchev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
MVVM
Asked by
Jason
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
Jason
Top achievements
Rank 1
Share this question
or