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

Local array built from DataSource and bound (MVVM) to Chart doesn't update when data source items change

3 Answers 143 Views
MVVM
This is a migrated thread and some comments may be shown as answers.
Jon
Top achievements
Rank 1
Jon asked on 02 Jul 2013, 07:06 PM
I'm trying to build a grid that displays a set of users, in this example 5 users, and a pie chart that displays those 5 users' licenses and a block of 5 unused licenses for a total of 10 licenses. This jsbin demonstrates the grid and chart. Click the delete button. Notice the grid removes and row but the chart does not reflect the change.

My question is why doesn't the chartDataSource get refreshed when the gridDataSource's data changes?

I found this post and it does provide a workaround but I don't see why the chartDataSource function doesn't get called when model.get('gridDataSource') is used inside of it and clearly the gridDataSource changes.

Here is a jsbin that demonstrates the workaround.

Thanks,
Jon

3 Answers, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 04 Jul 2013, 01:54 PM
Hi Jon,

Thank you for getting in touch with us.

The problem comes from the fact that the chart is bound to a calculated field which returns arrays of objects. This array however is not connected to the Grid's dataSource which is why any changes made in the grid will not reflect on the chart.

The solution is to bind both components to one DataSource. This way the dataSource will be shared and any changes that are made by the user will be automatically applied on both widgets.

For your convenience I updated the jsBin sample:

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
Jon
Top achievements
Rank 1
answered on 04 Jul 2013, 04:49 PM
Thanks for the updated jsbin. This was actually the first thing I tried and it does work just like the shared datasource example shows.

My need is for the chart to show the percentage of the total for each individual license and the remaining unassigned licenses as a single pie slice. The grid needs only to show a row for each individual license and should not show the unassigned licenses. This is what led to the calculated field for the chart.

Doesn't the calculated field recalculate when the underlying observable changes? 

PS the email that was sent as a reply had the word sibscribe instead of subscribe.
0
Alexander Valchev
Telerik team
answered on 08 Jul 2013, 09:07 AM
Hello Jon,

Thank you for the clarification.

Regarding your question, doesn't the calculated field recalculate when the underlying observable changes?

Generally speaking it does, however in case you use DataSource, the change of its data will not trigger the change of the viewModel field. In other words, when you remove a record from the Grid (respectively from the DataSource) you change the data, but not the DataSource instance itself. ViewModel does not know about changes in the data unless you manually force the event to trigger.

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
Jon
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
Jon
Top achievements
Rank 1
Share this question
or