I have followed the online demo, save gird settings and I have encountered a few issues.
If I change the column order, so I have columns a, b, c, d, e and I change them to b, a, c, d, e The change is not recorded. However the column widths are saved, along with any other grid changes.
If I select to display just columns a, d and save the settings, this works. However If I then select to show columns b by using the context menu, a third column is shown, however not necessarily b. However if after I save the settings then refresh the page, the correct columns are shown.
So the main issue is that column orders are not saved and when selecting what columns to show, they are not the correct columns (untill page re-load)
My code below,
I call the function GridSettingsPersister.vb that is provided with the demo. Any help with this would be much appreciated.
If I change the column order, so I have columns a, b, c, d, e and I change them to b, a, c, d, e The change is not recorded. However the column widths are saved, along with any other grid changes.
If I select to display just columns a, d and save the settings, this works. However If I then select to show columns b by using the context menu, a third column is shown, however not necessarily b. However if after I save the settings then refresh the page, the correct columns are shown.
So the main issue is that column orders are not saved and when selecting what columns to show, they are not the correct columns (untill page re-load)
My code below,
Partial Class ucGridRowClick |
Inherits System.Web.UI.UserControl |
Private _Datasource As DataTable |
Private dataGrid As DataRadGrid |
Public Property Datasource() As DataTable |
Get |
Return _Datasource |
End Get |
Set(ByVal value As DataTable) |
_Datasource = value |
End Set |
End Property |
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load |
standardGrid() |
If Not IsPostBack Then |
Dim hdn_field As HiddenField = TryCast(Page.Master.FindControl("hdn_pageId"), HiddenField) |
dataGrid = New DataRadGrid |
dataGrid.pageId = New Guid(hdn_field.Value.ToString()) |
dataGrid.coreEntityId = Session.Item("RealId") |
Dim gridSettings As String = dataGrid.LoadSettings() |
If gridSettings <> "" Then |
Dim LoadPersister As New GridSettingsPersister(RadGrid1) |
LoadPersister.LoadSettings(gridSettings) |
End If |
End If |
End Sub |
Protected Sub standardGrid() |
Dim boundColumn As GridBoundColumn |
If Not IsPostBack Then |
For Each column As DataColumn In Datasource.Columns |
If column.ColumnName.ToString() <> "ROWCLICK" Then |
boundColumn = New GridBoundColumn |
RadGrid1.MasterTableView.Columns.Add(boundColumn) |
boundColumn.DataField = column.ColumnName |
boundColumn.HeaderText = column.ColumnName.Replace("_", " ") |
boundColumn.DataFormatString = "<nobr>{0}</nobr>" |
Else |
boundColumn = New GridBoundColumn |
RadGrid1.MasterTableView.Columns.Add(boundColumn) |
boundColumn.DataField = column.ColumnName |
boundColumn.HeaderText = column.ColumnName |
boundColumn.Visible = False |
End If |
Next |
End If |
RadGrid1.MasterTableView.VirtualItemCount = Datasource.Rows.Count() |
RadGrid1.DataSource = Datasource |
RadGrid1.DataBind() |
End Sub |
Protected Sub RadGrid1_ItemCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.ItemCommand |
If e.CommandName = "saveGrid" Then |
saveGridSettings() |
ElseIf e.CommandName = "excel" Then |
buildExport("excel") |
ElseIf e.CommandName = "pdf" Then |
buildExport("pdf") |
End If |
End Sub |
Protected Sub RadGrid1_NeedDataSource(ByVal source As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles RadGrid1.NeedDataSource |
RadGrid1.DataSource = Datasource |
End Sub |
Sub saveGridSettings() |
Dim hdn_field As HiddenField = TryCast(Page.Master.FindControl("hdn_pageId"), HiddenField) |
Dim SavePersister As New GridSettingsPersister(RadGrid1) |
dataGrid = New DataRadGrid |
dataGrid.pageId = New Guid(hdn_field.Value.ToString()) |
dataGrid.coreEntityId = Session.Item("RealId") |
dataGrid.gridSettings = SavePersister.SaveSettings.ToString() |
dataGrid.SaveSettings() |
End Sub |
<telerik:RadGrid ID="RadGrid1" |
runat="server" |
GridLines="Vertical" |
ShowGroupPanel="True" |
AllowSorting="true" |
AllowPaging="true" |
AllowCustomPaging="false" |
AutoGenerateColumns="false" |
EnableHeaderContextMenu="true" |
Skin="Default" |
PageSize="15" |
OnNeedDataSource="RadGrid1_NeedDataSource" > |
<ExportSettings> |
<Pdf FontType="Subset" PaperSize="A4" /> |
<Excel Format="Html" /> |
<Csv ColumnDelimiter="Comma" RowDelimiter="NewLine" /> |
</ExportSettings> |
<MasterTableView DataKeyNames="ROWCLICK" CommandItemDisplay="Top" PagerStyle-AlwaysVisible="true" ClientDataKeyNames="ROWCLICK" > |
<PagerStyle Mode="Advanced"></PagerStyle> |
<CommandItemTemplate> |
<asp:LinkButton ID="btn_save" runat="server" CommandName="saveGrid" ><asp:Image runat="server" ID="img_save" ImageUrl="~/_resources/images/icons/tick.png"/></asp:LinkButton> |
<asp:LinkButton ID="btn_excel" runat="server" CommandName="excel" ><asp:Image runat="server" ID="Image1" ImageUrl="~/_resources/images/icons/xls_grey.gif"/></asp:LinkButton> |
</CommandItemTemplate> |
</MasterTableView> |
<ClientSettings ReorderColumnsOnClient="True" |
AllowDragToGroup="True" |
AllowColumnsReorder="True" |
EnablePostBackOnRowClick="False" |
AllowGroupExpandCollapse="True" > |
<Selecting AllowRowSelect="true" /> |
<ClientEvents OnRowClick="RowClick" /> |
<Resizing AllowRowResize="True" |
AllowColumnResize="True" |
EnableRealTimeResize="True" |
ResizeGridOnColumnResize="False"> |
</Resizing> |
</ClientSettings> |
</telerik:RadGrid> |
I call the function GridSettingsPersister.vb that is provided with the demo. Any help with this would be much appreciated.