开发者

Save infragistics column chooser changes

How to save changes to a ultra g开发者_运维知识库rid column choosers after the user choose the columns he want to see C# code


This is something i've had to deal with in the past - so my answer isn't Infragistics specific and is quite generic.

One thing I recommend very strongly is to preserve the column properties in a non-vendor-specific format. This will take you a little more time, but long term it is time well spent (that extra time is more design and thinking time, rather than development time).

What do you need to save?
Here are some of the things you can save from the columns:

  • width (when the user resizes a column)
  • current sort order
  • current grouping
  • any grid or column filters
  • column position (if you allow the user to move columns around)
  • column visibility

This is already shaping up to be a reasonably complex data object. Next you need to think about how you want to persist this information:

  • in a database?
  • using a call to a webservice?
  • in a local configuration file?
  • or a combination of these?

You also need to consider:

  • can the user save multiple layouts for the same grid?
  • or do you have multiple grids in your app for which you need to save layouts?

This is where my advice to think carefully and use non-vendor specific data objects comes in to it.


Let me tell you a story about the time that...

Previously i had to do this for a DevExpress ASPx grid, this particular component provides a function to get all the column info serialized to a string which you can then save to the database. This was all easy and good - until i needed to start tracking some column properties that DevExpress didn't include in that string (we had to go to clients and tell them that their favorite grid layouts that they had saved were no good and they needed to redo them for the new release of the product).

So i came up with a new data object designed to hold a column's properties, let's call it ColProperties, and there was one for each possible column in the grid. This was great, but i made the mistake of including a few DevExpress and System specific objects in it. This all worked for a while until we decided to use a WCF service call to save and reload these ColProperties objects, and those DevExpress and System objects were not serializable so the data object needed to be refactored again and we had to go back to the clients and tell them that their favorite layouts needed to be thrown away and redone...

To really make the story more interesting, we then changed the application from being a ASP.Net UI to a Silverlight one using the Telerik grid - but we still had to use the same layouts the users had previously saved. By this time we were using a properly designed data object to store the column properties and WCF calls to persist and retrieve the layouts, this massive change in application architecture meant zero change to the layouts functionality (we could go back to the clients and say "guess what - you can still use your old layouts!").

To summarize that long story...

Now if you are still reading this and haven't fallen asleep, you may say "but my grid is easy, i only have one of them, i don't need all that functionality". If this is your situation then by all means use a quick and dirty solution to save the column layout info.
However if the road map for your product is still wide open, or there is even the slightest possibility that you may change your grid in the future (or add more grids), or you may change how you save the user's selected layouts, or you may change or add more properties to be saved, then you need to consider what i've told you. An extra couple of hours spent designing it properly now can save you a lot of headaches in the future.


The UltraGrid.DisplayLayout property exposes many Save and SaveAsXml method overloads which allow you to save the entire state of the display layout (including user customizations) to a binary or XML file. Then to load a layout file, you can use one of the Load or LoadFromXml method overloads, depending on the format of the saved layout file.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜