RadControls version |
2010 (should work with earlier versions)
|
.NET version |
.Net4 (should work with earlier)
|
Visual Studio version |
VS2010 -- as Web Site so earlier versions should be able to load
|
programming language |
C#
|
browser support |
all browsers supported by RadControls
|
PROJECT DESCRIPTION
I have been spending a bit of time trying to get a simple and elegant way to (re-)format an export from a RadGrid. The Css Styles (especially if you do not use the built-in skins) are not carried through to the export. It is possible to customize the export with a little creativity.
The export creates XHTML which is then passed to the appropriate engine to produce the download file. The solution (once you find it) is pretty clean. It would be nice to have this engine directly exposed (I can think of many re-uses!) and documented.... wish list..
First, I created a Css.Resx file which contains the following items:
- GridItem
- GridItemCell
- GridHeaderItem
- GridHeaderItemCell
- GridItem
- GridItemCell
Each of these items contain a definition in classic style sheet format.
- color:#0000FF;
- font-size:1.2em;
So you can now define the appearance of each of these six regions (you can do more regions using the same pattern).
Setting up to detect the Export
Telerik examples typically shows the use of an independent button which then sets a variable. We use a similar pattern but make use of the built-in commands and a property on the RadGrid. This is done by adding two event handlers (with supporting code) as shown below. We use the CssClass as a flag variable.
The routines below may be put into a utility library and made universally available.
We use a function that breaks apart the CSS into a sorted list that is shown in the code. The function is (reasonably) tolerant of format. You could use
- .GridItemCell { whatever }
instead of just the content shown above.
There are a few got-cha, for example:
- color:Red; does not work.
- color: #FF0000; does work.
Those are discovered quickly (if it does not work, try an alternative expression!). I suspect that the CSS level is not comprehensive – so don’t be surprise if some items do not work! Hopefully Telerik will improve the support here (now that there's an example of customization).
I would love to see an event added that passes in the generated XHTML just before it goes to the rendering engine so I can modify it when needed.
With the formatting being in a RESX file, it is easy to modify as needed for different customers. You can modify as few or as many formatting attributes as you wish.