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

Implement Radgrid batch edit dynamically

3 Answers 326 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Shouvik
Top achievements
Rank 1
Shouvik asked on 14 Apr 2014, 12:14 PM
Hello,
My application is already using Telerik radgrid and I need to implement Batch Editing on it.
See the following .ascx code:
<telerik:RadGrid ID="dgEscrow" runat="server" GridLines="None" EnableEmbeddedSkins="false" AutoGenerateColumns="false" ShowFooter="true" CssClass="esGridTable">
    <HeaderStyle Font-Bold="true" HorizontalAlign="Center" />
    <ClientSettings>
        <ClientEvents OnGridCreated="setScrollerDimensionsEscrow" />
        <Scrolling AllowScroll="true" SaveScrollPosition="true" />
    </ClientSettings>
</telerik:RadGrid>

See the followinng .ascx.vb code:
Public Sub BindDG(Optional ByVal isPrintPage As Boolean = False)
        Dim edt As New EscrowDataTable(TractGID)
        Dim dt As DataTable = edt.GetDataTable
        Dim dv As DataView = dt.DefaultView
 
         With dgEscrow
            .CellSpacing = 0
            .ItemStyle.CssClass = "esGridRow"
            .AlternatingItemStyle.CssClass = "esGridRow"
        End With
 
 
        dgEscrow.DataSource = dv
        dgEscrow.DataBind()
    End Sub


On the above scenario, I need to implement Batch Editing but needs to be done all on the code behind because the number of columns and the column type may vary every time.

Please let us know if you guys need any more details.

Thanks,
Shouvik

3 Answers, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 16 Apr 2014, 06:42 AM
Hello Shouvik,

For handling such requirement you could have a look at the following online help article:
Once you create your grid programmatically you could set the relevant properties and attach event handlers for server-side or client-side event (in the same manner as you would in the markup).

As a simple example, setting the EditMode to Batch could be achieved with the following:
RadGrid1.MasterTableView.EditMode = GridEditMode.Batch

For detailed information about Batch editing functionality you could refer to the following help article:
Hope that helps.


Regards,
Konstantin Dikov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Shouvik
Top achievements
Rank 1
answered on 17 Apr 2014, 09:03 AM
Thanks Konstantin Dikov for your reply. 
I tried few of the things but still I am unable to edit the grid cells.
I have pasted all the relevant code.

Please see the following code I tried
ascx code:
<telerik:RadGridID="dgEscrow"runat="server"GridLines="None"EnableEmbeddedSkins="false"AutoGenerateColumns="false"ShowFooter="true"CssClass="esGridTable">
   <MasterTableViewEditMode="Batch"CommandItemDisplay="TopAndBottom"AutoGenerateColumns="False">
       <BatchEditingSettingsEditType="Row"OpenEditingEvent="DblClick"/>
         
   </MasterTableView>
    <HeaderStyleFont-Bold="true"HorizontalAlign="Center"/>
    <ClientSettings>
        <ClientEventsOnGridCreated="setScrollerDimensionsEscrow"/>
        <ScrollingAllowScroll="true"SaveScrollPosition="true"/>
    </ClientSettings>
</telerik:RadGrid>

ascx.vb code:
#Region " Public Methods "
  
  
    'This gets called before page load since we're calling it from a seperate USercontrol.
    Public Sub BindDG(Optional ByVal isPrintPage As Boolean = False)
  
        'The data table is fetched from the below code
        Dim edt As New EscrowDataTable(TractGID)
        Dim dt As DataTable = edt.GetDataTable
        Dim dv As DataView = dt.DefaultView
  
  
        'Sometimes this function gets run through twice after a sort. Make sure we're not duplicating columns.
        Session("NoRecords") = False
        Static bDynamicColumnsAdded As Boolean = False
  
        If (Not bDynamicColumnsAdded) Then
            AddDynamicColumns(dt)
            bDynamicColumnsAdded = True
        End If
  
        With dgEscrow
            .CellSpacing = 0
            .ItemStyle.CssClass = "esGridRow"
            .AlternatingItemStyle.CssClass = "esGridRow"
            If m_bPrintMode Then
                .BorderWidth = Unit.Pixel(1)
                .BorderColor = Color.FromName("#999999")
                lnkGoTop.Visible = False
                dgEscrow.Visible = True
            Else
                .BorderWidth = Unit.Pixel(0)
            End If
        End With
  
  
        'Get sort from session.
        Dim sOrderBy As String = CurrentUserSettings.SortOrderExpression.Split(":")(0)
        If (String.IsNullOrWhiteSpace(sOrderBy)) Then 'TFS #84058
            sOrderBy = "escEscrowNum" 'Default sort
        End If
        'TFS# 90866
        If sOrderBy.Equals("RecentUpdates") Then
            sOrderBy = sOrderBy + " DESC"
        End If
        dv.Sort = sOrderBy
        dgEscrow.DataSource = dv
        dgEscrow.DataBind()
  
  
  
  
  
    End Sub
  
#End Region
  
#Region " Private Methods "
  
    'Add formatted columns for each dynamic column in the datatable.
    Private Sub AddDynamicColumns(ByVal dt As DataTable)
        'Skip to dynamic columns.
        Dim InvisibleCount As Integer = 0
        For Each col As DataColumn In dt.Columns
            If (col.Ordinal >= m_iDataTableFirstCustomCol) Then
  
                'LOAD extended properties to use in custom datagrid columns & set initially in EscrowDataTable.GetDataTable method.
                Dim sDataType As String = Convert.ToString(col.ExtendedProperties("CustomDataType"))
                Dim iFCN As Integer = Integer.Parse(col.ExtendedProperties("FCN"))
                Dim bExtView As Boolean = Convert.ToBoolean(col.ExtendedProperties("ExtView"))
                Dim Hide As Boolean = Convert.ToBoolean(col.ExtendedProperties("IsHidden"))
                Dim strHeader As String = Convert.ToString(col.ExtendedProperties("ColHeader"))
                'Create new custom bound column.
                'This is where we override the Grid column and not sure if this is causing any issue.
                Dim boundCol As New fascBoundColumn
                'Dim boundCol As New GridBoundColumn
  
                dgEscrow.MasterTableView.DataKeyNames = New String() {"EscrowGID"}
                dgEscrow.MasterTableView.Columns.Add(boundCol)
  
                With boundCol
                    .DataType = sDataType
                    .FCN = iFCN
                    .PrintMode = m_bPrintMode
                    .DataField = col.ColumnName
                    .HeaderText = strHeader
                    If (Hide = True) Then
                        .Visible = False
                    End If
                    'Format alignment according to data type.
                    Select Case sDataType
                        Case "String"
                            .ItemStyle.HorizontalAlign = HorizontalAlign.Left
  
                        Case "Date", "DateAndTime", "Boolean"
                            .ItemStyle.HorizontalAlign = HorizontalAlign.Center
  
                        Case "Money", "Integer"
                            .ItemStyle.HorizontalAlign = HorizontalAlign.Right
                            .FooterStyle.HorizontalAlign = HorizontalAlign.Right
                    End Select
                End With
  
                'Don't show column to external users if marked.
                If (Not IsInRole("EscrowModify")) AndAlso (bExtView = False) Then
                    boundCol.Visible = False
                End If
  
                  
                'dgEscrow.Columns.Add(boundCol)
  
                If boundCol.Visible = False Then
                    InvisibleCount = InvisibleCount + 1
                End If
            End If
        Next
  
        If dgEscrow.Columns.Count = InvisibleCount Then
            If (Convert.ToBoolean(Session("DiableExcel"))) Then
                Session("DiableExcel") = True
            End If
            ltlGridStatus.Text = "All columns are Hidden for this community!"
            dgEscrow.Visible = False
        Else
            Session("DiableExcel") = False
        End If
    End Sub
  
     
  
      
    Private Sub SetFrozenColumns()
        If Convert.ToBoolean(CurrentUserSettings.EscrowGridScrolling) = True Then
            dgEscrow.ClientSettings.Scrolling.FrozenColumnsCount = 3
        Else
            dgEscrow.ClientSettings.Scrolling.FrozenColumnsCount = 0
        End If
    End Sub
     
#End Region


Please let me know what needs to be done next.

Thanks,
Shouvik
0
Konstantin Dikov
Telerik team
answered on 22 Apr 2014, 07:15 AM
Hello Shouvik,

Due to the missing references, the code snippet that you have provided is not enough to create a runnable project out of it, so it is hard to determine what could cause the issue on your end.

Nevertheless, I have noticed that you have a handler assigned for the client-side OnGridCreated event of the grid, so please ensure that you have setScrollerDimensionsEscrow defined. Furthermore, since any JavaScript error on the page could break the control functionality (and especially the Batch Editing), please ensure that there are no errors present on the page. You could do that by opening Developers Tools window in the browser and inspect the console for any errors.

If you continue to experience any issues with this, please open a regular ticket with sample, runnable project attached, so we could inspect it locally.


Regards,
Konstantin Dikov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
Shouvik
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Shouvik
Top achievements
Rank 1
Share this question
or