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

Column freeze not working when grid is added as a control to Treeview nodes

1 Answer 71 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mark Kelly
Top achievements
Rank 1
Mark Kelly asked on 13 Oct 2010, 05:42 PM

Hi, I have a radtree control and I am adding radgrid to its node programmatically.
I am setting the Scroll options on the grid to freeze the first two columns of the grid. However, the columns are not getting frozen? Any idea why..
I am setting the following properties on the grid.

grid.ClientSettings.Scrolling.UseStaticHeaders = True
grid.ClientSettings.Scrolling.SaveScrollPosition = True
grid.ClientSettings.Scrolling.FrozenColumnsCount =  2

Also, I observe that now for all grids on the different nodes the grid's height is consant. I would want a variable height for the grid, depending on the number of records it has. How do I accomplish that?

Thanks

 

 

 

 

1 Answer, 1 is accepted

Sort by
0
Dimo
Telerik team
answered on 19 Oct 2010, 09:20 AM
Hi Mark Kelly,

The described scenario is not supported out-of-the-box, as RadGrid needs to be visible on initial page load to adjust its frozen and non-frozen columns. You can use the following approach:

<%@ Page Language="C#" %>
<%@ Import Namespace="System.Data" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
 
<script runat="server">
 
protected void RadGrid_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
    DataTable dt = new DataTable();
    DataRow dr;
    int colsNum = 14;
    int rowsNum = 6;
    string colName = "Column";
 
    for (int j = 1; j <= colsNum; j++)
    {
        dt.Columns.Add(String.Format("{0}{1}", colName, j));
    }
 
    for (int i = 1; i <= rowsNum; i++)
    {
        dr = dt.NewRow();
 
        for (int k = 1; k <= colsNum; k++)
        {
            dr[String.Format("{0}{1}", colName, k)] = String.Format("{0}{1} Row{2}", colName, k, i);
        }
        dt.Rows.Add(dr);
    }
 
    (sender as RadGrid).DataSource = dt;
}
 
</script>
  
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  
<head runat="server">
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<title>RadControls</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
 
<telerik:RadTreeView ID="RadTreeView1" runat="server" OnClientNodeExpanded="repaintGrid">
    <Nodes>
        <telerik:RadTreeNode Text="ExpandMe">
            <Nodes>
                <telerik:RadTreeNode>
                    <NodeTemplate>
                        <telerik:RadGrid
                            ID="RadGrid1"
                            runat="server"
                            Width="800px"
                            AllowSorting="true"
                            OnNeedDataSource="RadGrid_NeedDataSource">
                            <ClientSettings>
                                <Scrolling AllowScroll="true" UseStaticHeaders="true" FrozenColumnsCount="1" />
                                <ClientEvents OnGridCreated="getID" />
                            </ClientSettings>
                        </telerik:RadGrid>
                    </NodeTemplate>
                </telerik:RadTreeNode>
            </Nodes>
        </telerik:RadTreeNode>
    </Nodes>
</telerik:RadTreeView>
 
<script type="text/javascript">
 
var gridID;
 
function getID(sender, args)
{
    gridID = sender.get_id();
}
 
function repaintGrid(sender, args)
{
        var grid = $find(gridID);
        grid.get_masterTableView().get_element().style.tableLayout = "auto";
        grid.get_masterTableViewHeader().get_element().style.tableLayout = "auto";
        grid._scrolling._initializeDimensions();
}
 
</script>
 
</form>
</body>
</html>


Kind regards,
Dimo
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
Mark Kelly
Top achievements
Rank 1
Answers by
Dimo
Telerik team
Share this question
or