Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
715
Field Chooser, Save customization and dynamic columns
posted

Hello,

i use a xamDataGrid with a SQL Data Binding to the DataSource and the autoGenerateFields is set to true.

In my application, the end user can save the layout of the xamdatagrid with the Savecustomization method. It work very fine but when the underlying SQL statement change (ie. add column or remove column), the loadCustomization don't work anymore.

How i can handle this in order to persist the layout?

Helps will be appreciated,

Thanks,

Pierre

  • 34810
    Verified Answer
    Offline posted in reply to BUI Pierre

    Hello Pierre,

    I would like you to take a look at the following forum thread, where an issue very similar to this one has recently been discussed: http://ko.infragistics.com/community/forums/t/50173.aspx.

    Essentially, the bits to take from this forum thread is that the SaveCustomizations and LoadCustomizations methods are designed to handle end user customizations to the XamDataGrid. By default, removal of a column is not something that an end user can do by default, and so as soon as a column is removed, the LoadCustomizations will not work, because there exists a Field in the saved layout that the XamDataGrid no longer knows about. You are correct in that when doing the addition of columns, the LoadCustomizations works. I was clearly mistaken on that part of my initial response, but this works because the columns that are saved in the SaveCustomizations method still exist when you go to load your customizations.

    My recommendation for you on this matter is to keep track of whether or not the columns collection in your XamDataGrid changes in the way that a column is removed when you load a new SQL statement-driven data table into your XamDataGrid. You could do this by keeping a List<string> and keeping track of the column names in your data table. This would work because since you are auto-generating the fields in your grid, the XamDataGrid will create a field for every column that exists in the bound data table's view. If all of the columns exist for each of the names in your List<string> when you have loaded in your new SQL statement, the LoadCustomizations method should work, assuming the FieldLayoutInitialized event of the XamDataGrid did not fire, because that will mean the XamDataGrid created a new FieldLayout for your fields, which is likely happening when you remove the column from your grid, as well.

    If the column names do not match, then the LoadCustomizations method will not work for you here. In this case, I would recommend that you use the XmlDocument class to read in the file you are saving to and recursively parse it to get your customizations loaded into the grid. This file will contain all of the information about your fields that you need, such as the row and column that the field exists in. By getting this information by parsing your saved file, you can get the Fields in your XamDataGrid by going through the XamDataGrid.FieldLayouts[field layout index].Fields collection and assigning a new ActualPosition to those Fields. This property takes a FieldPosition object, and you can use its constructor to specify the row and column that you wish that field to show up at. Note, that this will still not work for the columns that have been removed, though, as there will not be a column in the bound data source of the XamDataGrid that corresponds to that particular field.

    If you would like to see the LoadCustomizations method in the XamDataGrid work when fields have been removed from the grid, I would suggest that you place a new product idea for it at http://ideas.infragistics.com. This site places you in direct communication with our product management teams who plan and prioritize new features and products based on community and user feedback.

    Please let me know if you have any other questions or concerns on this matter.

    Sincerely,
    Andrew
    Associate Developer
    Infragistics Inc.
    www.infragistics.com/support

  • 715
    Offline posted in reply to Andrew Goldenbaum

    Hello Andrew,

    yes your impression is correct: the xamdatagrid is bound to a datatable. The datatable is filled by a sql statement. I save the custom layout (A). I change the sql result (remove one column and add two new column). In my app, i load the custom layout (A) and i see it not work.

    In fact my sql statement have a pivot statement which produce dynamic columns based on the data. So i can not do what you say: toggling the visibility column.

    One thing i notice that;

    when the sql statement provide new column (ie added column) from the last result, the Load/Save customization work. But when one column was removed, the save/load customizations doesn't' work anymore.

    I look for a way to resolve this issue.


    Pierre

  • 34810
    Offline posted

    Hello Pierre,

    Thank you for your post.

    While I am not extremely familiar with SQL operations when data binding, I imagine that since the XamDataGrid requires some sort of IEnumerable to bind to in order to display data, you are querying your data base and then loading the data into a data table or collection of some sort, which is then bound to the XamDataGrid. Then, you are saving the layout customizations, and changing the underlying SQL statements. Please let me know if this is incorrect, as my following response goes off of this impression.

    When you save the customizations of a XamDataGrid, you essentially save the fields that currently exist in the grid, and when you try loading the customizations, the resultant content of the file that is being loaded needs to match these fields. If a field has been completely removed, or one is added, the customizations will not be loaded, as the field collection differs from the one in the file or stream that you saved to. Also, you will want to check if the FieldLayout that you have when you save your customizations is the same one as the one when you are going to load your customizations as well. You can do this by hooking the FieldLayoutInitialized event of the XamDataGrid before you change the underlying SQL statement. If this event fires, you are getting a new FieldLayout, and the customizations will not load correctly.

    One thing that the save and load customizations does take into effect is whether or not a field is visible or hidden. So, if you would like to continue using the SaveCustomizations and LoadCustomizations methods of the XamDataGrid, you may want to consider toggling the Visibility of the columns that you wish to show in the grid, rather than removing or adding them by modifying the underlying SQL statement.

    Please let me know if you have any other questions or concerns on this matter.

    Sincerely,
    Andrew
    Associate Developer
    Infragistics Inc.
    www.infragistics.com/support