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

[Solved] CV. Saving detail table grid settings on a per user basis

4 Answers 294 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Priya
Top achievements
Rank 1
Priya asked on 25 May 2009, 04:33 AM
hi,
I have implemented

  Saving grid settings on a per user basis
but my grid is a hierarchical one.i want to keep detail tables' settings like sort order in the database on a per user basis

  the code for Saving grid settings on a per user basis

  'this method should be called on Pre_Render of grid  
        Public Function ReadSettings() As String  
            Try  
                Dim gridSettings() As Object = New Object((6) - 1) {}  
                'Save sort expressions  
                gridSettings(0) = CType(gridInstance.MasterTableView.SortExpressions, IStateManager).SaveViewState  
 
                'Save groupBy  
                Dim groupByExpressions As GridGroupByExpressionCollection = gridInstance.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(1) = groupExpressions  
 
                'Save visible columns  
                Dim columnsLength As Integer = (gridInstance.MasterTableView.Columns.Count + gridInstance.MasterTableView.AutoGeneratedColumns.Length)  
                Dim columnOrder() As Pair = New Pair(columnsLength - 1) {}  
                Dim allColumns As ArrayList = New ArrayList(columnsLength)  
                Dim visibleColumns As ArrayList = New ArrayList(columnsLength)  
 
                allColumns.AddRange(gridInstance.MasterTableView.Columns)  
                allColumns.AddRange(gridInstance.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  
                    visibleColumns.Add(column.Visible)  
                    i = (i + 1)  
                Next  
                gridSettings(2) = columnOrder  
                gridSettings(3) = visibleColumns  
 
               'Save PageSize  
                gridSettings(4) = CType(gridInstance.PageSize, Object)  
                'Save detail grid sort expressions  
                Dim nextindextosave As Integer = 5 
                'If you have several detail tables at a level then you can get the count of the detailtables in the grid using the following code:  
 
                If gridInstance.MasterTableView.DetailTables.Count > 0 Then  
                    Dim j As Integer  
                    For j = 0 To gridInstance.MasterTableView.DetailTables.Count - 1  
                        'If you want to check the count of the detailtables at each level of the grid, then you would have to try the following code:  
                        If gridInstance.MasterTableView.DetailTables(j).DetailTables.Count > 0 Then  
                            ReDim gridSettings(gridSettings.Length + gridInstance.MasterTableView.DetailTables(j).DetailTables.Count)  
                        Else  
                 gridSettings(5) = CType(gridInstance.MasterTableView.DetailTables(j).SortExpressions, IStateManager).SaveViewState  
                          
                        End If  
                    Next  
                End If  
             Dim formatter As LosFormatter = New LosFormatter  
                Dim writer As StringWriter = New StringWriter  
                formatter.Serialize(writer, gridSettings)  
                Return writer.ToString  
              Catch ex As Exception  
                Throw ex  
            End Try  
        End Function  
 
 
        'this method should be called on PageInit  
        Public Function LoadSettings(ByVal settings As String)  
            Try  
                If ((settings = "") Or (settings Is DBNull.Value)) Then  
                    Return False  
                End If  
                Dim formatter As LosFormatter = New LosFormatter()  
                Dim reader As StringReader = New StringReader(settings)  
                Dim gridSettings() As Object = CType(formatter.Deserialize(reader), Object())  
 
                'Load sort expressions  
                Me.gridInstance.MasterTableView.SortExpressions.Clear()  
                CType(Me.gridInstance.MasterTableView.SortExpressions, IStateManager).LoadViewState(gridSettings(0))  
                'Load groupBy  
                Dim groupByExpressions As GridGroupByExpressionCollection = Me.gridInstance.MasterTableView.GroupByExpressions  
                groupByExpressions.Clear()  
                Dim groupExpressionsState As Object() = CType(gridSettings(1), 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)  
                    countcount = count + 1  
                Next  
 
                'load visible columns  
                Dim columnsLength As Integer = (Me.gridInstance.MasterTableView.Columns.Count + Me.gridInstance.MasterTableView.AutoGeneratedColumns.Length)  
                Dim columnOrder() As Pair = CType(gridSettings(2), Pair())  
                Dim visibleCols As ArrayList = CType(gridSettings(3), ArrayList)  
 
                If columnsLength = columnOrder.Length Then  
                    Dim allColumns As ArrayList = New ArrayList(columnsLength)  
                    allColumns.AddRange(Me.gridInstance.MasterTableView.Columns)  
                    allColumns.AddRange(Me.gridInstance.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, Unit)  
                        column.Visible = CType(visibleCols(i), Boolean)  
                        ii = i + 1  
                    Next  
                End If  
                'Load page size  
                Me.gridInstance.PageSize = CType(gridSettings(4), Integer)  
 
                    If gridInstance.MasterTableView.DetailTables.Count > 0 Then  
                    Dim j As Integer  
                    For j = 0 To gridInstance.MasterTableView.DetailTables.Count - 1  
                        'If you want to check the count of the detailtables at each level of the grid, then you would have to try the following code:  
                        If gridInstance.MasterTableView.DetailTables(j).DetailTables.Count > 0 Then  
                            Me.gridInstance.MasterTableView.DetailTables(j).SortExpressions.Clear()  
                            CType(Me.gridInstance.MasterTableView.DetailTables(j).SortExpressions, IStateManager).LoadViewState(gridSettings(5))  
                            ReDim gridSettings(gridSettings.Length + gridInstance.MasterTableView.DetailTables(j).DetailTables.Count)  
                        Else  
                          Me.gridInstance.MasterTableView.DetailTables(j).SortExpressions.Clear()  
                            CType(Me.gridInstance.MasterTableView.DetailTables(j).SortExpressions, IStateManager).LoadViewState(gridSettings(5))  
 
                        End If  
                    Next  
                End If  
          Catch ex As Exception  
                Throw ex  
            End Try  
        End Function 

This is working fine for master grid..

But for detail table ie,gridsettings(5) its not working

plz help me

4 Answers, 1 is accepted

Sort by
0
Denis
Top achievements
Rank 1
answered on 25 May 2009, 03:50 PM
Hey,

I also have the same exact problem. I have found my child grid, and have saved the settings, but how do I load them, since the settings are supposed to be loaded on Page_Init (which is not possible for child grids from what I tried...)?

Thanks!
0
Tsvetoslav
Telerik team
answered on 27 May 2009, 10:29 AM
Hello Denis, hello Priya,

Please, find the attached to this post a sample that demonstrates how to save the settings of child tables of the grid's master table view.

Best regards,
Tsvetoslav
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.
0
Priya
Top achievements
Rank 1
answered on 09 Jun 2009, 09:37 AM

hi,

now another problem..As I called the

If e.Item.OwnerTableView.Name = "TableViewProduct" Then 'detailtablename  
            Dim objGridPageSettingsbal As GridProfileGridPageSettingsBal  
            objGridPageSettingsbal = New GridProfileGridPageSettingsBal(RadProduct.MasterTableView)  
            objGridPageSettingsbal.LoadExpandedStates(LoadSettings())  
        End If 

its going to endless loop


 Protected Sub RadProduct_DetailTableDataBind(ByVal source As Object, ByVal e As Telerik.Web.UI.GridDetailTableDataBindEventArgs) Handles RadProduct.DetailTableDataBind  
        e.DetailTableView.DataSource = initdatasetsub()  
    End Sub  
 
    Protected Sub RadProduct_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadProduct.ItemDataBound  
        If e.Item.OwnerTableView.Name = "TableViewProduct" Then  
            Dim objGridPageSettingsbal As GridProfileGridPageSettingsBal  
            objGridPageSettingsbal = New GridProfileGridPageSettingsBal(RadProduct.MasterTableView)  
            objGridPageSettingsbal.LoadExpandedStates(LoadSettings())  
        End If  
    End Sub  
 
    Protected Sub RadProduct_NeedDataSource(ByVal source As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles RadProduct.NeedDataSource  
        RadProduct.DataSource = initdatasetmain()  
    End Sub  
 
    
    Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init  
        Try  
            If Not IsPostBack Then  
                Dim objGridPageSettingsbal As GridProfileGridPageSettingsBal  
                objGridPageSettingsbal = New GridProfileGridPageSettingsBal(RadProduct.MasterTableView)  
                objGridPageSettingsbal.LoadSettings(LoadSettings())  
            End If  
        Catch ex As Exception  
 
        End Try  
    End Sub  
    Private Function LoadSettings() As String  
        Dim settingvalue As StringString = String.Empty  
        Try  
            Dim objGridPageSettingsbal As New GridProfileGridPageSettingsBal(RadProduct.MasterTableView)  
            objGridPageSettingsbal.UserID = 1 
            objGridPageSettingsbal.PageID = GridProfileGridPageSettingsBal.Page.PAGE_HOMEPAGE  
            objGridPageSettingsbal.GridID = GridProfileGridPageSettingsBal.Grid.GRID_HOMEPAGE_WorkDetailsGrid  
            Dim ds As New DataSet  
            ds = objGridPageSettingsbal.FetchGridProfileSettings()  
            If (ds.Tables(0).Rows.Count > 0) Then  
                settingvalue = CType(ds.Tables(0).Rows(0)("PageGridSettings"), String)  
            Else  
                settingvalue = objGridPageSettingsbal.ReadSettings()  
            End If  
        Catch ex As Exception  
            
        End Try  
        Return settingvalue  
    End Function  
 
    Protected Sub RadProduct_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadProduct.PreRender  
        Try  
            Dim PageSettingId As Integer  
            Dim objGridPageSettingsbal As New GridProfileGridPageSettingsBal(RadProduct.MasterTableView)  
            Dim settingvalue As String = objGridPageSettingsbal.ReadSettings()  
            objGridPageSettingsbal.UserID = 1 
            objGridPageSettingsbal.PageID = GridProfileGridPageSettingsBal.Page.PAGE_HOMEPAGE  
            objGridPageSettingsbal.GridID = GridProfileGridPageSettingsBal.Grid.GRID_HOMEPAGE_WorkDetailsGrid  
            objGridPageSettingsbal.LastModifiedOn = DateTime.Today  
            objGridPageSettingsbal.PageGridSettings = settingvalue 
            'objGridPageSettingsbal.FilterSettings = ReadFilterSettings()  
            Dim ds As New DataSet()  
            ds = objGridPageSettingsbal.FetchGridProfileSettings()  
            If (ds.Tables(0).Rows.Count > 0) Then  
                PageSettingId = ds.Tables(0).Rows(0)("PageSettingId")  
                objGridPageSettingsbal.PageSettingID = PageSettingId 
                objGridPageSettingsbal.UpdateGridProfileSettings()  
            Else  
                PageSettingId = objGridPageSettingsbal.SaveGridProfileSettings()  
            End If  
        Catch ex As Exception  
                   End Try  
    End Sub 
plz help me
0
Tsvetoslav
Telerik team
answered on 10 Jun 2009, 10:49 AM
Hello Priya,

The code provided in your last post does not provide enough information to locate the reason for the endless loop that you are observing since you are implementing the settings persister class differently than the sample I have sent.

I'd suggest you to open a formal support ticket and send a test project so that I can debug it on my end and get back to you with more information.

All the best,
Tsvetoslav
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
Priya
Top achievements
Rank 1
Answers by
Denis
Top achievements
Rank 1
Tsvetoslav
Telerik team
Priya
Top achievements
Rank 1
Share this question
or