This is a migrated thread and some comments may be shown as answers.

Sharing column definitions among multiple grids

1 Answer 52 Views
Grid
This is a migrated thread and some comments may be shown as answers.
andieje
Top achievements
Rank 1
andieje asked on 09 Jul 2009, 08:55 PM
Hi

I would like to share my column definitions among several different rad grids. I was thinking about using a skin file within the website theme to do this but then I remembered that i want some of the grids to be grouped and not others.

How could i achieve this? These were my thoughts

1) Add the column and grouping settings to the skin and then remove the grouping definitions programatically from the grid that doesnt need grouping. I don't know if this is possible because i know you can't override properties set in the skin file of a theme

2)  define the column definitions in the skin file and add the groupings programmatically to the grids that need to be grouped

3) perhaps i can define the column definitions in the skin file and add the groupings declaratively to the grids that need to be grouped. Not much between 2 and 3 really. Is 3 even possible?

This is all i could think of. I was hoping there might be something better than this!

many thanks

1 Answer, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 13 Jul 2009, 12:57 PM
Hello andieje,

All approaches are possible. We would personally recommend defining your generic columns and settings in the Skin file and adding (not removing) additional functionality for every individual grid.

Here is a sample approach. RadGrid uses Northwinds sample AccessDataSource:

<telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="ProductsDataSource"
    <MasterTableView> 
        <GroupByExpressions> 
            <telerik:GridGroupByExpression> 
                <GroupByFields> 
                    <telerik:GridGroupByField FieldName="CategoryID" /> 
                </GroupByFields> 
                <SelectFields> 
                    <telerik:GridGroupByField FieldName="CategoryID" /> 
                </SelectFields> 
            </telerik:GridGroupByExpression> 
        </GroupByExpressions> 
    </MasterTableView> 
</telerik:RadGrid> 

The second grid uses the same skin and does not define grouping:

<telerik:RadGrid ID="RadGrid2" runat="server" DataSourceID="ProductsDataSource"
</telerik:RadGrid> 

All columns and other settings (hierarchy load mode, width, etc.) are defined in the Skin file:

<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
 
<telerik:RadGrid runat="server" AutoGenerateColumns="false" Width="600px"
    <MasterTableView GroupLoadMode="Client" GroupsDefaultExpanded="false"
        <Columns> 
            <telerik:GridNumericColumn DataField="ProductID" HeaderText="ProductID" NumericType="number" 
                AllowRounding="true" DataType="System.Int32"
            </telerik:GridNumericColumn> 
            <telerik:GridBoundColumn DataField="ProductName" HeaderText="ProductName"
            </telerik:GridBoundColumn> 
            <telerik:GridNumericColumn DataField="CategoryID" HeaderText="CategoryID" NumericType="number" 
                AllowRounding="true" DataType="System.Int32"
            </telerik:GridNumericColumn> 
            <telerik:GridNumericColumn DataField="UnitPrice" HeaderText="UnitPrice" NumericType="Currency" 
                AllowRounding="true"
            </telerik:GridNumericColumn> 
            <telerik:GridNumericColumn DataField="UnitsInStock" HeaderText="UnitsInStock" NumericType="Number" 
                AllowRounding="true" DataType="System.Int32"
            </telerik:GridNumericColumn> 
        </Columns> 
    </MasterTableView> 
</telerik:RadGrid> 

The result is as expected. The first grid has grouping defined, the second doesn't. They both share the same column setup inherited from the skin definition. Attached is a screenshot.

Greetings,
Veli
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
andieje
Top achievements
Rank 1
Answers by
Veli
Telerik team
Share this question
or