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?
9 Answers, 1 is accepted
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.
Kind regards!
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.
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.
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.
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.
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 RowLoaded, RowIsExpandedChanged 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.
Tina Stancheva
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.