PresistenceFramework not save groups!

10 posts, 1 answers
  1. Paweł
    Paweł avatar
    26 posts
    Member since:
    Jun 2011

    Posted 14 Aug 2012 Link to this post

    Hello!

    We are developing an application using Telerik Controls. When we stand in front of use Presitence Framework, we found that this is not saving groups in RadGridViews

    We are using MVVM Light, all RadGridViews ItemSource are bound to ViewModels, all columns are autogenerated.

    Saving grouping state is very important in our project - what could we have done wrong?
  2. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 17 Aug 2012 Link to this post

    Hi Paweł,

    In order to persist the RadGridView control, you need to create a CustomPropertyProvider. I attached a sample solution demonstrating a GridViewCustomPropertyProvider that saves the filters, sorting and grouping in the GridView control. Please let me know if it works for you.

    Regards,
    Tina Stancheva
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. UI for WPF is Visual Studio 2017 Ready
  4. Paweł
    Paweł avatar
    26 posts
    Member since:
    Jun 2011

    Posted 21 Aug 2012 Link to this post

    Ok, it is working fine (after few mods), but how can I save that stream to isolated storage?
    Kind regards!
  5. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 21 Aug 2012 Link to this post

    Hi Paweł,

    In order to save the settings of the RadGridView in an isolated storage, you need to define the PersistenceManager.StorageId attached property in the RadGridView definition:
    <telerik:RadGridView x:Name="gridView" telerik:PersistenceManager.StorageId="xRadGridView"
            Grid.Column="1"
            ItemsSource="{Binding}" />

    Then in you can implement the following OnSave() and OnLoad() methods:
    private void OnSave(object sender, System.Windows.RoutedEventArgs e)
    {
        IsolatedStorageProvider isoStorageProvider = new IsolatedStorageProvider();
        isoStorageProvider.SaveToStorage();
    }
     
    private void OnLoad(object sender, System.Windows.RoutedEventArgs e)
    {
        IsolatedStorageProvider isoStorageProvider = new IsolatedStorageProvider();
        isoStorageProvider.LoadFromStorage();
    }

    You can find more information in our online documentation. Let us know if it helps.

    Regards,
    Tina Stancheva
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  6. Paweł
    Paweł avatar
    26 posts
    Member since:
    Jun 2011

    Posted 21 Aug 2012 Link to this post

    It is not saving whole data - i.e. expanded groups, selected rows
  7. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 21 Aug 2012 Link to this post

    Hi Paweł,

    As the RadPersistenceFramework cannot save the settings of the RadGridView out-of-the-box, we've implemented the approach with defining custom property provider. The purpose of the property providers is to allow you to define which properties of complex controls like the RadGridView should be persisted. The GridViewCustomPropertyProvider defined in the sample solution I sent you is a basic implementation demonstrating how to persist the Columns UniqueName, Header, Width and DisplayOrder as well as the filters, sortings and the groupings implemented in the RadGridView. This is why you'll need to extend the class to save the other properties that your application should persist.

    Basically  the GetCustomProperties method should return a list of all RadGridView persisted properties. The ProvideValue() method should implement the logic that saves the properties and the RestoreValue() method should include logic that will restore the saved values.

    Let us know if you encounter any issues while extending the GridViewCustomPropertyProvider.

    Regards,
    Tina Stancheva
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  8. Paweł
    Paweł avatar
    26 posts
    Member since:
    Jun 2011

    Posted 22 Aug 2012 Link to this post

    I've implemented it and it works fine, but is there any oportunity to write GridViewCustomPropertyProvider results into isolated storage?
  9. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 22 Aug 2012 Link to this post

    Hello Paweł,

    The CustomPropertyProvider defines only the logic that the PersistenceFramework should use when saving a set of properties - in your case it controls which RadGridView properties to be saved and how. Where to save the properties is determined by the PersistenceFramework saving approach you've chosen. This is why as long as you use the IsolatedStorageProvider.SaveToStorage() method, the properties defined in the GridViewCustomPropertyProvider will be saved in the isolated storage.

    Regards,
    Tina Stancheva
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  10. Paweł
    Paweł avatar
    26 posts
    Member since:
    Jun 2011

    Posted 22 Aug 2012 Link to this post

    How to persist actualy expanded groups and selected row in GridViewCustomPropertyProvider?
    All RadGridViews data persisting well, but only SelectedItems persist for only one RadGridView in projects. I've been debugging it, but in some RadGridViews loading data providing correct model, but couldn't find it in gridView.Items, other cases just do not load any "SelectedItems" properties, although it has been saved.
  11. Answer
    Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 27 Aug 2012 Link to this post

    Hi Paweł,

    I attached a sample solution demonstrating how to extend the GridViewCustomPropertyProvider to persist the selected rows as well as the expanded rows. I defined a Hiererchical RadGridView to demonstrate how you can persist the settings of a nested GridView as well. 

    Basically it's important to note that you need a logic that keeps track of the selected and expanded rows. For that purpose we've defined a helper class that attached event handlers to the RadGridView  RowLoadedRowIsExpandedChanged and SelectionChanged. These events track the selected and expanded rows and based on a generated id, they populate two collections - with the selected and expanded ids. This helper class is then used to provide and restore the selected and expanded rows in the GridViewCustomPropertyProvider  so that the PersistenceFramework is aware of them and can properly save and load them.

    Please examine the solution and let me know if it helps.

    All the best,
    Tina Stancheva
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top
UI for WPF is Visual Studio 2017 Ready