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

Whats the best way to swap "Views"

7 Answers 113 Views
MVVM
This is a migrated thread and some comments may be shown as answers.
sitefinitysteve
Top achievements
Rank 2
Iron
Veteran
sitefinitysteve asked on 01 Apr 2013, 03:00 AM
If I have an array of items, and I want to display it either as a Listview or Kendo Grid (based on a toggle) what's the best way to go about that?...is there a demo somewhere?

I've got the toggle bound fine, and right now the listview works...but the only thing I can think to do is toggle visibility on the list-grid markup based on the view, and that seems WAYYY wasteful to me.

How would you do it?

7 Answers, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 02 Apr 2013, 04:08 PM
Hi Steve,

There is no Kendo Widget that supports dual display style.
Your current approach, which toggles the visibility state of widgets, seems to be OK.

Kind regards,
Alexander Valchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
sitefinitysteve
Top achievements
Rank 2
Iron
Veteran
answered on 02 Apr 2013, 04:24 PM
I don't need a widget to do it, just what's the "best" way to do it.

What I find gimped about this way is that I'm doing twice the processing.  Both "containers" are being updated at the same time...grid and listview both get bound when the data changes, but only one is visible...know what I mean?
0
Alexander Valchev
Telerik team
answered on 03 Apr 2013, 03:04 PM
Hi Steve,

In order to avoid the updating of the hidden widget you can unbind it from the shared DataSource.
var sharedDS = new kendo.data.DataSource({ /* ... */ });
//grid is initially bound to the sharedDS
 
//grid is hidden
grid.setDataSource(new kendo.data.DataSource()); //unbind the grid
 
//grid is shown
grid.setDataSource(sharedDS);

In this way the hidden widget (in that case the Grid) will not get updated when the sharedDS changes.
For more information please see the setDataSource method.

Kind regards,
Alexander Valchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
sitefinitysteve
Top achievements
Rank 2
Iron
Veteran
answered on 03 Apr 2013, 03:08 PM
...the shared DS is an MVVM viewmodel array though?  Both controls are setting their source to it...so this still applies?
0
Alexander Valchev
Telerik team
answered on 05 Apr 2013, 12:39 PM
Hi Steve,

Yes, you should be able to use the same approach. Did you tested the solution? Have you experienced any troubles?

Regards,
Alexander Valchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
sitefinitysteve
Top achievements
Rank 2
Iron
Veteran
answered on 05 Apr 2013, 12:42 PM
To be honest, no I didn't test it...bit confusing :)

I'm not manually (clearly) setting the DS on the grid or list, the view is binding them based on the data-bind source

So it seems like I would be bypassing MVVM as a concept to interact with the grid\list manually with this?
0
Alexander Valchev
Telerik team
answered on 09 Apr 2013, 08:20 AM
Hello Steve,

Generally speaking you should not have problems - MVVM concept should not break after rebinding the widget (in case the DataSource is part of the same ViewModel).
Please test the suggested solution and let me know if you encounter with any concrete issues.

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