I have persisted filter/sort settings from a XamGrid and now when I try to re-apply those settings when new columns have been added, the display shows all columns removed from the grid. How can older saved filter/sort settings be applied to grids that have new or removed columns?
Hi Gary,
Let me know if you have any further questions on this matter.
There's no setting that you can set but you can probably do something along the lines of:
1.) Keep track of what columns currently exist in the grid.2.) Load the grid settings (this may modify the columns collection)3.) See what columns now exist in the grid and compare them against the columns before the load4.) Remove or Add columns accordingly.
You can submit this as a product idea here: http://ideas.infragistics.com/
Sounds good, I will try this out. Is there any setting that would prevent it from removing/adding columns and just set the filters on the columns it could match up? If not, could this be entered as a new feature?
Hello Gary,
Thanks for the code. With that I was able to reproduce the issue and I think I found out why it behaves this way. In the code, the grid is being told to persist various properties. One of these properties (for example FilterColumnSettings) is being persisted for every column inside the Columns collection. What is not being persisted however, is the column's Key property. So when the settings are loaded back into the XamGrid and it now has differing numbers of columns, the FilterColumnSettings don't match up and it tries to find the column based on the Key. But the Key wasn't saved and this produces an EmptyColumnKeyException in the output window. After which the XamGrid disappears. (It doesn't really disappear but no longer renders the column headers and data)
To resolve this you need to persist the column Key property as well.
prop = new PropertyNamePersistenceInfo();prop.PropertyName = "Columns[].Key";settings.PropertySettings.Add(prop);
One thing you have to keep in mind though, is that if the columns differ from what was originally saved, the XamGrid is going to try and place back the original columns that were persisted. So it is going to remove any columns that were added after the save occurred and it is going to add columns that exist in the persisted data but no longer exist in the grid. It is restoring the state of the properties that were persisted.
Let me know if you have any questions on this.
I have built two persistence functions so that I can just pass in a XamGrid to save its values, instead of having to add persistence configuration to each grid's XAML, the code looks like below - I save and load from a file, but that code is not included here. I do not have this as an isolated example, but if I save a filter from a XamGridwith columns A, B and C and then load that filter into a XamGrid that has columns A, D, E, the row data in the XamGrid disappears (I believe the filter shows as set on the header columns). The reason this is an issue is it causes a versioning problem with saving filters for a grid and then adding a new column to that grid display, such that you have to re-create the filter and save it and throw away the old saved one. Any ideas on what may be going wrong here?
public static PersistenceSettings GetStandardGridPersistenceSettings()
{
PersistenceSettings settings = new PersistenceSettings();
settings.SavePersistenceOptions = PersistenceOption.OnlySpecified;
// Filter menu
PropertyNamePersistenceInfo prop = new PropertyNamePersistenceInfo();
prop.PropertyName = "RowFiltersCollection";
settings.PropertySettings.Add(prop);
prop = new PropertyNamePersistenceInfo();
prop.PropertyName = "Columns[].FilterColumnSettings";
// Maybe this is for top filter row?
prop.PropertyName = "FilteringSettings";
// Column sort
prop.PropertyName = "SortingSettings";
// Row grouping?
prop.PropertyName = "GroupBySettings";
// Column order?
prop.PropertyName = "ColumnMovingSettings";
// Column width?
prop.PropertyName = "ColumnResizingSettings";
// Visible columns?
prop.PropertyName = "ColumnChooserSettings";
return settings;
}
public static string SeralizeGridSettings(XamGrid grid)
string content = "";
using (MemoryStream mStream = PersistenceManager.Save(grid, GetStandardGridPersistenceSettings()))
mStream.Position = 0;
using (StreamReader sr = new StreamReader(mStream, Encoding.ASCII))
content = sr.ReadToEnd();
return content;
public static void DeSeralizeGridSettings(XamGrid grid, string gridSettings)
using (MemoryStream ms = new MemoryStream(Encoding.ASCII.GetBytes(gridSettings)))
ms.Position = 0;
PersistenceManager.Load(grid, ms, GetStandardGridPersistenceSettings());