I have a grid that is empty on page load, and columns change a few time (columns getting added from code behind, and column names get changed from code behind). I am unable to get the columns to size to the contents. Here is my code:
<
telerik:RadCodeBlock
ID
=
"RadCodeBlock1"
runat
=
"server"
>
<
script
type
=
"text/javascript"
>
function pageLoad() {
var grid = $find("<%= grdImportData.ClientID %>");
var columns = grid.get_masterTableView().get_columns();
var columnIndex = columns.length + 1;
columns[columnIndex].resizeToFit();
}
</
script
>
</
telerik:RadCodeBlock
>
<
telerik:RadGrid
runat
=
"server"
ID
=
"grdImportData"
RenderMode
=
"Lightweight"
AllowPaging
=
"true"
PageSize
=
"10"
OnNeedDataSource
=
"grdImportData_NeedDataSource"
OnPageIndexChanged
=
"grdImportData_PageIndexChanged"
OnUpdateCommand
=
"grdImportData_UpdateCommand"
OnDeleteCommand
=
"grdImportData_DeleteCommand"
OnItemCommand
=
"grdImportData_ItemCommand"
OnItemDataBound
=
"grdImportData_ItemDataBound"
AllowSorting
=
"False"
AlternatingItemStyle-BackColor
=
"#f5f5f5"
ItemStyle-BackColor
=
"#ffffff"
ColumnWidth
=
"Auto"
HorizontalAlignment
=
"Stretch"
>
<
ClientSettings
>
<
Scrolling
AllowScroll
=
"True"
SaveScrollPosition
=
"true"
FrozenColumnsCount
=
"1"
EnableVirtualScrollPaging
=
"true"
></
Scrolling
>
<
Resizing
AllowColumnResize
=
"true"
ResizeGridOnColumnResize
=
"true"
EnableRealTimeResize
=
"true"
AllowResizeToFit
=
"true"
/>
</
ClientSettings
>
<
MasterTableView
EditMode
=
"InPlace"
DataKeyNames
=
"Id"
>
<
Columns
>
<
telerik:GridEditCommandColumn
HeaderStyle-Width
=
"75px"
HeaderStyle-HorizontalAlign
=
"Right"
ItemStyle-HorizontalAlign
=
"Right"
/>
<
telerik:GridTemplateColumn
HeaderStyle-Width
=
"50px"
>
<
ItemTemplate
>
<
asp:LinkButton
runat
=
"server"
CommandName
=
"Delete"
><
i
class
=
"icon s7-junk grid-edit-icon"
></
i
></
asp:LinkButton
>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
</
Columns
>
</
MasterTableView
>
</
telerik:RadGrid
>