Whats the best way to swap "Views"

8 posts, 0 answers
  1. Steve
    Steve avatar
    1851 posts
    Member since:
    Dec 2008

    Posted 31 Mar 2013 Link to this post

    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?
  2. Alexander Valchev
    Admin
    Alexander Valchev avatar
    2877 posts

    Posted 02 Apr 2013 Link to this post

    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!
  3. Kendo UI is VS 2017 Ready
  4. Steve
    Steve avatar
    1851 posts
    Member since:
    Dec 2008

    Posted 02 Apr 2013 Link to this post

    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?
  5. Alexander Valchev
    Admin
    Alexander Valchev avatar
    2877 posts

    Posted 03 Apr 2013 Link to this post

    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!
  6. Steve
    Steve avatar
    1851 posts
    Member since:
    Dec 2008

    Posted 03 Apr 2013 Link to this post

    ...the shared DS is an MVVM viewmodel array though?  Both controls are setting their source to it...so this still applies?
  7. Alexander Valchev
    Admin
    Alexander Valchev avatar
    2877 posts

    Posted 05 Apr 2013 Link to this post

    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!
  8. Steve
    Steve avatar
    1851 posts
    Member since:
    Dec 2008

    Posted 05 Apr 2013 Link to this post

    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?
  9. Alexander Valchev
    Admin
    Alexander Valchev avatar
    2877 posts

    Posted 09 Apr 2013 Link to this post

    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!
Back to Top
Kendo UI is VS 2017 Ready