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

How to re-set width of master table view in javascript??

1 Answer 193 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Fatima
Top achievements
Rank 1
Fatima asked on 19 Feb 2009, 06:45 AM
Hi All!

I have made the grid scrollable and set the width of master table to "96%" n table layout = auto.
1. This is to avoid horizontal scrollbar when its vertically scrollable. But when my grid contains only 2-3 items i want to reset this width to 100% through javascript. How can i do this.

2. There is another question, i wanted to set headers fixed, but when i do this.. my grid looks very odd in terms of row height n width. Also there comes an unknown patch sort of at the end of row header and. my itemtemplate column dissappeares where i m displaying radio buttons. Any solution??

Thanks!



1 Answer, 1 is accepted

Sort by
0
Dimo
Telerik team
answered on 23 Feb 2009, 12:59 PM
Hello Fatima,

1. You can reset the MasterTableView's width to 100% like this:

<%@ 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 = 4
    int rowsNum = 2
    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" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
 
<html xmlns="http://www.w3.org/1999/xhtml"
<head runat="server"
<meta http-equiv="content-type" content="text/html; charset=utf-8" /> 
<title>RadControls for ASP.NET AJAX</title> 
</head> 
<body> 
<form id="form1" runat="server"
<asp:ScriptManager ID="ScriptManager1" runat="server" /> 
 
<telerik:RadGrid 
    ID="RadGrid1" 
    runat="server" 
    Skin="Vista" 
    Width="800px" 
    OnNeedDataSource="RadGrid_NeedDataSource"
    <MasterTableView Width="90%" /> 
    <ClientSettings> 
        <Scrolling AllowScroll="true" UseStaticHeaders="true" /> 
        <ClientEvents OnGridCreated="GridCreated" /> 
    </ClientSettings> 
</telerik:RadGrid> 
 
<script type="text/javascript"
 
function GridCreated(sender, args) 
    var masterTableHeader = sender.get_masterTableViewHeader().get_element(); 
    var masterTable = sender.get_masterTableView().get_element(); 
    if (masterTable.clientHeight < masterTable.parentNode.clientHeight
    { 
        masterTableHeader.parentNode.style.marginRight = "0px"
        masterTableHeader.parentNode.style.paddingRight = "16px"
        masterTable.style.width = "100%"
        masterTableHeader.style.width = "100%"
        masterTable.style.tableLayout = "auto"
        masterTableHeader.style.tableLayout = "auto"
        sender._scrolling.initializeAutoLayout(); 
        sender.repaint(); 
    } 
 
</script> 
 
</form> 
</body> 
</html> 
 



2. We will need your RadGrid declaration to see what's going on exactly.


Regards,
Dimo
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
Fatima
Top achievements
Rank 1
Answers by
Dimo
Telerik team
Share this question
or