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

Persisting user settings - Problems

3 Answers 56 Views
Grid
This is a migrated thread and some comments may be shown as answers.
mabs
Top achievements
Rank 1
mabs asked on 05 Jul 2010, 10:00 AM
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,

 
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 ObjectByVal 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 ObjectByVal 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 ObjectByVal 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.

3 Answers, 1 is accepted

Sort by
0
Accepted
Veli
Telerik team
answered on 07 Jul 2010, 03:36 PM
Hello Russell,

Note that you are using both advanced RadGrid databinding (using the NeedDataSource event) as well as simple databinding (setting data in Page_Load and calling DataBind) at the same time. Note that these two binding scenarios are not supported together. Additionally, for saving grid column settings using the GridSettingsPersister, we recommend avoiding simple databinding. So, consider removing the part where RadGrid is databound in Page_Load (inside the standardGrid() method call) and use the NeedDataSource event to bind the grid only. This is probably related to your columns OrderIndex not getting properly persisted.


Regards,
Veli
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
0
mabs
Top achievements
Rank 1
answered on 07 Jul 2010, 04:41 PM
Thank you, it works now!  Only problem, NeedDataSource seems to fire twice, cant seem to see why this would happen?
0
Veli
Telerik team
answered on 08 Jul 2010, 11:38 AM
Hi Russell,

Make sure you do not have excessive calls to RadGrid.Rebind() in your code. RadGrid will manage to rebind automatically for most of the cases.

Greetings,
Veli
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
mabs
Top achievements
Rank 1
Answers by
Veli
Telerik team
mabs
Top achievements
Rank 1
Share this question
or