4 Answers, 1 is accepted
0
Accepted
Shinu
Top achievements
Rank 2
answered on 03 Jun 2008, 07:35 AM
Hi,
Do the columns get resized when the AllowColumnResize property is set to true? I tried setting the Resize property with my Grid as shown below and is working properly.
ASPX:
Resizing columns
Thanks
Shinu.
Do the columns get resized when the AllowColumnResize property is set to true? I tried setting the Resize property with my Grid as shown below and is working properly.
ASPX:
| <ClientSettings > |
| <Resizing AllowColumnResize="true" ClipCellContentOnResize="true" /> |
| </ClientSettings> |
Resizing columns
Thanks
Shinu.
0
Markus
Top achievements
Rank 1
answered on 03 Jun 2008, 11:32 AM
Hello Shinu,
here is the code I use as you can see all properties are set but clipping is not working and the grid has always 100% width. I cannot make size of column smaler than content.
By the way the functions to load and save grid layout you descript in the help file are not working. To redo the problem adjust the connect string in Page_Load to your needs. Now move or resize a column and click on the checkbox to save settings. Now reload the page, the grid has original layout column size and order got lost.
Here the code:
ASPX
Code behind:
here is the code I use as you can see all properties are set but clipping is not working and the grid has always 100% width. I cannot make size of column smaler than content.
By the way the functions to load and save grid layout you descript in the help file are not working. To redo the problem adjust the connect string in Page_Load to your needs. Now move or resize a column and click on the checkbox to save settings. Now reload the page, the grid has original layout column size and order got lost.
Here the code:
ASPX
| <%@ Page Language="vb" AutoEventWireup="false" EnableEventValidation="false" CodeBehind="main.aspx.vb" Inherits="aspxMain" %> |
| <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> |
| <!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 id="Head1" runat="server"> |
| <title></title> |
| <link rel="stylesheet" type="text/css" href="css/styles.css" /> |
| </head> |
| <body> |
| <form id="frmMain" runat="server"> |
| <telerik:RadScriptManager ID="smMain" runat="server" EnableTheming="True"> |
| </telerik:RadScriptManager> |
| <telerik:RadAjaxManager ID="ramMain" runat="server" DefaultLoadingPanelID="ralpMain"> |
| <AjaxSettings> |
| <telerik:AjaxSetting AjaxControlID="rgrdBookingsOverview"> |
| <UpdatedControls> |
| <telerik:AjaxUpdatedControl ControlID="rgrdBookingsOverview" /> |
| </UpdatedControls> |
| </telerik:AjaxSetting> |
| <telerik:AjaxSetting AjaxControlID="chkValue"> |
| <UpdatedControls> |
| <telerik:AjaxUpdatedControl ControlID="chkValue" /> |
| <telerik:AjaxUpdatedControl ControlID="lblCurrentLayout" /> |
| </UpdatedControls> |
| </telerik:AjaxSetting> |
| </AjaxSettings> |
| </telerik:RadAjaxManager> |
| <table style="width: 100%"> |
| <tr> |
| <td> |
| <telerik:RadGrid ID="rgrdBookingsOverview" runat="server" AllowSorting="True" AutoGenerateColumns="False" DataSourceID="datBookingsOverview" GridLines="None" Skin="Office2007"> |
| <MasterTableView CommandItemDisplay="none" CurrentResetPageIndexAction="SetPageIndexToFirst" DataKeyNames="customerid" DataSourceID="datBookingsOverview" Dir="LTR" Frame="Border" GroupsDefaultExpanded="True" NoMasterRecordsText="Es sind keine Datensätze vorhanden." TableLayout="Auto"> |
| <RowIndicatorColumn CurrentFilterFunction="NoFilter" FilterListOptions="VaryByDataType" Visible="False"> |
| <HeaderStyle Width="20px" /> |
| </RowIndicatorColumn> |
| <ExpandCollapseColumn CurrentFilterFunction="NoFilter" FilterListOptions="VaryByDataType" Resizable="False" Visible="False"> |
| <HeaderStyle Width="20px" /> |
| </ExpandCollapseColumn> |
| <Columns> |
| <telerik:GridButtonColumn ButtonType="ImageButton" CommandName="EditData" CurrentFilterFunction="NoFilter" FilterListOptions="VaryByDataType" ImageUrl="images/dialog/edit.gif" Text="Datensatz ändern" UniqueName="EditDataColumn"> |
| </telerik:GridButtonColumn> |
| <telerik:GridButtonColumn ButtonType="ImageButton" CommandName="CancelData" ConfirmText="Datensatz wirklich stornieren?" CurrentFilterFunction="NoFilter" FilterListOptions="VaryByDataType" ImageUrl="images/dialog/delete.gif" Text="Datensatz stornieren" UniqueName="CancelDataColumn"> |
| </telerik:GridButtonColumn> |
| <telerik:GridBoundColumn CurrentFilterFunction="NoFilter" DataField="customerid" FilterListOptions="VaryByDataType" ForceExtractValue="None" HeaderText="customerid" SortExpression="customerid" UniqueName="customerid"> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn CurrentFilterFunction="NoFilter" DataField="companyname" FilterListOptions="VaryByDataType" ForceExtractValue="None" HeaderText="companyname" SortExpression="companyname" UniqueName="companyname"> |
| </telerik:GridBoundColumn> |
| </Columns> |
| <EditFormSettings> |
| <EditColumn CurrentFilterFunction="NoFilter" FilterListOptions="VaryByDataType"> |
| </EditColumn> |
| <PopUpSettings ScrollBars="None" /> |
| </EditFormSettings> |
| <HeaderStyle Font-Bold="false" /> |
| </MasterTableView><GroupingSettings CollapseTooltip="Gruppe verbergen" ExpandTooltip="Gruppe anzeigen" /> |
| <ClientSettings AllowColumnHide="True" AllowColumnsReorder="True" AllowKeyboardNavigation="True" ReorderColumnsOnClient="True"> |
| <Selecting AllowRowSelect="True" /> |
| <Resizing AllowColumnResize="True" EnableRealTimeResize="True" ResizeGridOnColumnResize="True" ClipCellContentOnResize="true" /> |
| </ClientSettings> |
| <ExportSettings> |
| <Pdf FontType="Subset" PaperSize="Letter" /> |
| <Excel Format="Html" /> |
| <Csv ColumnDelimiter="Comma" RowDelimiter="NewLine" /> |
| </ExportSettings> |
| <SortingSettings SortToolTip="Hier klicken um zu sortieren" /> |
| </telerik:RadGrid><asp:SqlDataSource ID="datBookingsOverview" runat="server"></asp:SqlDataSource> |
| <br /> |
| <asp:CheckBox ID="chkValue" runat="server" AutoPostBack="True" Text="Save gird layout (press F5 to update page and restore the grid layout)" /> |
| <br /> |
| <br /> |
| Current Layout: <asp:Label ID="lblCurrentLayout" runat="server"></asp:Label> |
| </td> |
| </tr> |
| </table> |
| </form> |
| </body> |
| </html> |
Code behind:
| Imports Telerik.Web.UI |
| Imports System.Collections |
| Imports System.IO |
| Imports System.Web.UI |
| Partial Public Class aspxMain |
| Inherits System.Web.UI.Page |
| Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load |
| Dim strSQL As String |
| datBookingsOverview.ConnectionString = "server=jabba;database=northwind;integrated security=True" |
| strSQL = "SELECT customerid,companyname from customers where customerid like 'bo%'" |
| datBookingsOverview.SelectCommand = strSQL |
| LoadGridLayoutFromString(rgrdBookingsOverview, CStr(Session("Layout"))) |
| lblCurrentLayout.Text = CStr(Session("Layout")) |
| End Sub |
| Public Shared Function SaveGridLayoutToString(ByVal objGrid As RadGrid) As String |
| Try |
| Dim gridSettings() As Object = New Object((4) - 1) {} |
| 'Save groupBy |
| Dim groupByExpressions As GridGroupByExpressionCollection = objGrid.MasterTableView.GroupByExpressions |
| Dim groupExpressions() As Object = New Object((groupByExpressions.Count) - 1) {} |
| Dim count As Integer = 0 |
| For Each expression As GridGroupByExpression In groupByExpressions |
| groupExpressions(count) = CType(expression, IStateManager).SaveViewState |
| count = (count + 1) |
| Next |
| gridSettings(0) = groupExpressions |
| 'Save sort expressions |
| gridSettings(1) = CType(objGrid.MasterTableView.SortExpressions, IStateManager).SaveViewState |
| 'Save columns order |
| Dim columnsLength As Integer = (objGrid.MasterTableView.Columns.Count + objGrid.MasterTableView.AutoGeneratedColumns.Length) |
| Dim columnOrder() As Pair = New Pair(columnsLength) {} |
| Dim allColumns As ArrayList = New ArrayList(columnsLength) |
| allColumns.AddRange(objGrid.MasterTableView.Columns) |
| allColumns.AddRange(objGrid.MasterTableView.AutoGeneratedColumns) |
| Dim i As Integer = 0 |
| For Each column As GridColumn In allColumns |
| Dim p As Pair = New Pair |
| p.First = column.OrderIndex |
| p.Second = column.HeaderStyle.Width |
| columnOrder(i) = p |
| i = (i + 1) |
| Next |
| gridSettings(2) = columnOrder |
| 'Save filter expression |
| gridSettings(3) = CType(objGrid.MasterTableView.FilterExpression, Object) |
| Dim formatter As LosFormatter = New LosFormatter |
| Dim writer As StringWriter = New StringWriter |
| formatter.Serialize(writer, gridSettings) |
| Return writer.ToString |
| Catch objEx As Exception |
| Throw |
| End Try |
| End Function |
| Public Shared Sub LoadGridLayoutFromString(ByVal objGrid As RadGrid, ByVal strLayoutString As String) |
| Try |
| If strLayoutString = "" Then Exit Sub |
| Dim formatter As LosFormatter = New LosFormatter |
| Dim reader As StringReader = New StringReader(strLayoutString) |
| Dim gridSettings() As Object = CType(formatter.Deserialize(reader), Object()) |
| 'Load groupBy |
| Dim groupByExpressions As GridGroupByExpressionCollection = objGrid.MasterTableView.GroupByExpressions |
| groupByExpressions.Clear() |
| Dim groupExpressionsState() As Object = CType(gridSettings(0), Object()) |
| Dim count As Integer = 0 |
| For Each obj As Object In groupExpressionsState |
| Dim expression As GridGroupByExpression = New GridGroupByExpression |
| CType(expression, IStateManager).LoadViewState(obj) |
| groupByExpressions.Add(expression) |
| count = (count + 1) |
| Next |
| 'Load sort expressions |
| objGrid.MasterTableView.SortExpressions.Clear() |
| CType(objGrid.MasterTableView.SortExpressions, IStateManager).LoadViewState(gridSettings(1)) |
| 'Load columns order |
| Dim columnsLength As Integer = (objGrid.MasterTableView.Columns.Count + objGrid.MasterTableView.AutoGeneratedColumns.Length) |
| Dim columnOrder() As Pair = CType(gridSettings(2), Pair()) |
| If (columnsLength = columnOrder.Length) Then |
| Dim allColumns As ArrayList = New ArrayList(columnsLength) |
| allColumns.AddRange(objGrid.MasterTableView.Columns) |
| allColumns.AddRange(objGrid.MasterTableView.AutoGeneratedColumns) |
| Dim i As Integer = 0 |
| For Each column As GridColumn In allColumns |
| column.OrderIndex = CType(columnOrder(i).First, Integer) |
| column.HeaderStyle.Width = CType(columnOrder(i).Second, WebControls.Unit) |
| i = (i + 1) |
| Next |
| End If |
| 'Load filter expression |
| objGrid.MasterTableView.FilterExpression = CType(gridSettings(3), String) |
| Catch objEx As Exception |
| Throw |
| End Try |
| End Sub |
| Protected Sub CheckBox1_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs) Handles chkValue.CheckedChanged |
| Session("Layout") = SaveGridLayoutToString(rgrdBookingsOverview) |
| lblCurrentLayout.Text = CStr(Session("Layout")) |
| End Sub |
| End Class |
0
Hi Markus,
When you choose auto-layout for your grid table the column widths cannot be reduced more than the size of the text content they hold. This is the expected behavior and can be simulated with any other resizable html table. If you would like to shrink the column width to further extent, consider setting MasterTableView -> TableLayout to Fixed.
Additionally, I double-checked the implementation for grid settings persistence on a per user basis from this documentation topic and everything seemed to be in order. Verify that you intercepted the Init/Render events as specified in the article and the code which stores/recovers the settings is executed (debugging your code).
Best regards,
Stephen
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
When you choose auto-layout for your grid table the column widths cannot be reduced more than the size of the text content they hold. This is the expected behavior and can be simulated with any other resizable html table. If you would like to shrink the column width to further extent, consider setting MasterTableView -> TableLayout to Fixed.
Additionally, I double-checked the implementation for grid settings persistence on a per user basis from this documentation topic and everything seemed to be in order. Verify that you intercepted the Init/Render events as specified in the article and the code which stores/recovers the settings is executed (debugging your code).
Best regards,
Stephen
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
0
Markus
Top achievements
Rank 1
answered on 05 Jun 2008, 11:20 AM
Hello Shinu,
thanks for information, cell resizing is now working!
the other problem I already tried to put the code to "Page_Init" and "Page_PreRender" (I cannot find an event with name "Render") but it is still not working. Here is the code I use:
Regards Markus
thanks for information, cell resizing is now working!
the other problem I already tried to put the code to "Page_Init" and "Page_PreRender" (I cannot find an event with name "Render") but it is still not working. Here is the code I use:
| Imports Telerik.Web.UI |
| Imports System.Collections |
| Imports System.IO |
| Imports System.Web.UI |
| Partial Public Class aspxMain |
| Inherits System.Web.UI.Page |
| Private Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init |
| LoadGridLayoutFromString(rgrdBookingsOverview, CStr(Session("Layout"))) |
| lblCurrentLayout.Text = CStr(Session("Layout")) |
| End Sub |
| Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load |
| Dim strSQL As String |
| datBookingsOverview.ConnectionString = "server=jabba;database=northwind;integrated security=True" |
| strSQL = "SELECT customerid,companyname from customers where customerid like 'bo%'" |
| datBookingsOverview.SelectCommand = strSQL |
| End Sub |
| Public Shared Function SaveGridLayoutToString(ByVal objGrid As RadGrid) As String |
| Try |
| Dim gridSettings() As Object = New Object((4) - 1) {} |
| 'Save groupBy |
| Dim groupByExpressions As GridGroupByExpressionCollection = objGrid.MasterTableView.GroupByExpressions |
| Dim groupExpressions() As Object = New Object((groupByExpressions.Count) - 1) {} |
| Dim count As Integer = 0 |
| For Each expression As GridGroupByExpression In groupByExpressions |
| groupExpressions(count) = CType(expression, IStateManager).SaveViewState |
| count = (count + 1) |
| Next |
| gridSettings(0) = groupExpressions |
| 'Save sort expressions |
| gridSettings(1) = CType(objGrid.MasterTableView.SortExpressions, IStateManager).SaveViewState |
| 'Save columns order |
| Dim columnsLength As Integer = (objGrid.MasterTableView.Columns.Count + objGrid.MasterTableView.AutoGeneratedColumns.Length) |
| Dim columnOrder() As Pair = New Pair(columnsLength) {} |
| Dim allColumns As ArrayList = New ArrayList(columnsLength) |
| allColumns.AddRange(objGrid.MasterTableView.Columns) |
| allColumns.AddRange(objGrid.MasterTableView.AutoGeneratedColumns) |
| Dim i As Integer = 0 |
| For Each column As GridColumn In allColumns |
| Dim p As Pair = New Pair |
| p.First = column.OrderIndex |
| p.Second = column.HeaderStyle.Width |
| columnOrder(i) = p |
| i = (i + 1) |
| Next |
| gridSettings(2) = columnOrder |
| 'Save filter expression |
| gridSettings(3) = CType(objGrid.MasterTableView.FilterExpression, Object) |
| Dim formatter As LosFormatter = New LosFormatter |
| Dim writer As StringWriter = New StringWriter |
| formatter.Serialize(writer, gridSettings) |
| Return writer.ToString |
| Catch objEx As Exception |
| Throw |
| End Try |
| End Function |
| Public Shared Sub LoadGridLayoutFromString(ByVal objGrid As RadGrid, ByVal strLayoutString As String) |
| Try |
| If strLayoutString = "" Then Exit Sub |
| Dim formatter As LosFormatter = New LosFormatter |
| Dim reader As StringReader = New StringReader(strLayoutString) |
| Dim gridSettings() As Object = CType(formatter.Deserialize(reader), Object()) |
| 'Load groupBy |
| Dim groupByExpressions As GridGroupByExpressionCollection = objGrid.MasterTableView.GroupByExpressions |
| groupByExpressions.Clear() |
| Dim groupExpressionsState() As Object = CType(gridSettings(0), Object()) |
| Dim count As Integer = 0 |
| For Each obj As Object In groupExpressionsState |
| Dim expression As GridGroupByExpression = New GridGroupByExpression |
| CType(expression, IStateManager).LoadViewState(obj) |
| groupByExpressions.Add(expression) |
| count = (count + 1) |
| Next |
| 'Load sort expressions |
| objGrid.MasterTableView.SortExpressions.Clear() |
| CType(objGrid.MasterTableView.SortExpressions, IStateManager).LoadViewState(gridSettings(1)) |
| 'Load columns order |
| Dim columnsLength As Integer = (objGrid.MasterTableView.Columns.Count + objGrid.MasterTableView.AutoGeneratedColumns.Length) |
| Dim columnOrder() As Pair = CType(gridSettings(2), Pair()) |
| If (columnsLength = columnOrder.Length) Then |
| Dim allColumns As ArrayList = New ArrayList(columnsLength) |
| allColumns.AddRange(objGrid.MasterTableView.Columns) |
| allColumns.AddRange(objGrid.MasterTableView.AutoGeneratedColumns) |
| Dim i As Integer = 0 |
| For Each column As GridColumn In allColumns |
| column.OrderIndex = CType(columnOrder(i).First, Integer) |
| column.HeaderStyle.Width = CType(columnOrder(i).Second, WebControls.Unit) |
| i = (i + 1) |
| Next |
| End If |
| 'Load filter expression |
| objGrid.MasterTableView.FilterExpression = CType(gridSettings(3), String) |
| Catch objEx As Exception |
| Throw |
| End Try |
| End Sub |
| Protected Sub CheckBox1_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs) Handles chkValue.CheckedChanged |
| Session("Layout") = SaveGridLayoutToString(rgrdBookingsOverview) |
| lblCurrentLayout.Text = CStr(Session("Layout")) |
| End Sub |
| Private Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender |
| Session("Layout") = SaveGridLayoutToString(rgrdBookingsOverview) |
| lblCurrentLayout.Text = CStr(Session("Layout")) |
| End Sub |
| End Class |
Regards Markus