[OPEN] [#1877] Grouped Datagrid loses selection by DataBind

  1. #1

    [OPEN] [#1877] Grouped Datagrid loses selection by DataBind

    Hi Fabrício,


    I upgraded to Ext.NET 5.3. So far it works. But now it loses the selection when I work with grouping. Here is the new code.

    Imports Ext.Net
    
    Public Class grid2
    
        Inherits System.Web.UI.Page
    
        Dim aktGrid As New GridPanel
    
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    
            Dim aktResourceManager As New ResourceManager
            With aktResourceManager
                .ID = "rm"
                .Theme = Ext.Net.Theme.Neptune
            End With
    
            With aktGrid
    
                .ID = "mwgrid"
                .Width = 700
                .Height = 350
    
                .SelectionModel.Clear()
                .View.Clear()
                .Plugins.Clear()
                .ColumnModel.Columns.Clear()
                .Features.Clear()
                .Store.Clear()
    
                .EnableLocking = True
    
                Dim _Store As New Store
                _Store.ID = "store1"
    
                Dim _Model As New Model
    
                _Model.IDProperty = "Col1"
    
                For i As Integer = 1 To 10
    
    
                    If i = 1 Then
                        _Model.Fields.Add(New ModelField("Col" & i.ToString, ModelFieldType.Int))
                    Else
                        _Model.Fields.Add(New ModelField("Col" & i.ToString, ModelFieldType.String))
                    End If
    
                Next
    
                _Store.Model.Add(_Model)
    
                _Store.DataSource = Me.Data
    
                .Store.Add(_Store)
    
                With .ColumnModel
    
                    For i As Integer = 1 To 10
    
                        Dim _Col As Object
    
                        If i = 1 Then
                            _Col = New NumberColumn
                        Else
                            _Col = New Column
                        End If
    
                        _Col.ID = "Col" & i.ToString
                        _Col.Text = "Col" & i.ToString
                        _Col.DataIndex = "Col" & i.ToString
    
                        If i = 1 Then _Col.Locked = True
    
                        .Columns.Add(_Col)
    
                    Next
    
                End With
    
    
                Dim _RowSelModel As New RowSelectionModel
    
                With _RowSelModel
                    .Mode = SelectionMode.Single
                End With
    
                .SelectionModel.Add(_RowSelModel)
    
                .Features.Add(New Grouping)
    
                Dim _View As New GridView
                _View.StripeRows = True
                _View.TrackOver = True
    
                .View.Add(_View)
    
            End With
    
            Dim _button As New Button("Databind")
            AddHandler _button.DirectEvents.Click.Event, AddressOf Click
            _button.ID = "databind"
    
            Page.FindControl("form1").Controls.Add(aktResourceManager)
            Page.FindControl("form1").Controls.Add(aktGrid)
            Page.FindControl("form1").Controls.Add(_button)
    
            If Not Ext.Net.ExtNet.IsAjaxRequest Then
    
                aktGrid.Store(0).GroupField = "Col2"
    
                Dim RM As RowSelectionModel = aktGrid.GetSelectionModel
                If RM.SelectedRows.Count = 0 Then
                    RM.SelectedRows.Add(New SelectedRow(5))
                    RM.UpdateSelection()
                End If
    
            End If
    
    
        End Sub
    
        Private Sub Click(sender As Object, e As DirectEventArgs)
    
            aktGrid.Store(0).DataBind()
    
        End Sub
    
    
        Private ReadOnly Property Data As Object()
            Get
    
                Data = New Object() {New Object() {1, "test1", "test1", "test1", "test1", "test1", "test1", "test1", "test1", "test1"},
                New Object() {2, "test1", "test1", "test1", "test1", "test1", "test1", "test1", "test1", "test1"},
                New Object() {3, "test1", "test1", "test1", "test1", "test1", "test1", "test1", "test1", "test1"},
                New Object() {4, "test1", "test1", "test1", "test1", "test1", "test1", "test1", "test1", "test1"},
                New Object() {5, "test1", "test1", "test1", "test1", "test1", "test1", "test1", "test1", "test1"},
                New Object() {6, "test1", "test1", "test1", "test1", "test1", "test1", "test1", "test1", "test1"},
                New Object() {7, "test1", "test1", "test1", "test1", "test1", "test1", "test1", "test1", "test1"},
                New Object() {8, "test1", "test1", "test1", "test1", "test1", "test1", "test1", "test1", "test1"},
                New Object() {9, "test1", "test1", "test1", "test1", "test1", "test1", "test1", "test1", "test1"},
                New Object() {10, "test1", "test1", "test1", "test1", "test1", "test1", "test1", "test1", "test1"},
                New Object() {11, "test1", "test1", "test1", "test1", "test1", "test1", "test1", "test1", "test1"}}
    
            End Get
    
        End Property
    
    End Class
  2. #2
    Hello Gidi!

    I have moved your post to a new thread as, it seems, the focus has shifted from "Locking" to "Grouping". I was able to reproduce the issue, locking didn't affect the behavior in this case, but we'll need a bit more time to check the code and better understand the problem + suggest a fix.

    We'll post back soon.
    Fabrício Murta
    Developer & Support Expert
  3. #3
    Hello again, Gidi!

    We still need to check this in-depth to define how exactly the selection is lost; but actually it is only "visually" lost, the selected record is kept, which allows to easily correct the problem when it happens.

    So, as a workaround you can just call the grid view's Refresh() method when providing new data, if that's a grouped grid.

    From your test case, it should suffice to add, between lines 100 and 101, the following:

    _button.DirectEvents.Click.Success = "App.mwgrid.getView().refresh()"
    We have logged the issue under #1877 in our GitHub bug tracking repository and will post an update here as soon as we get a definitive fix pushed upstream.

    Refreshing the view is reasonably light on resources, and we expect it not to affect negatively the user experience and performance.

    Hope this helps!
    Fabrício Murta
    Developer & Support Expert

Similar Threads

  1. Replies: 3
    Last Post: Jun 15, 2023, 9:48 PM
  2. [CLOSED] Locked Datagrid loses selection by DataBind
    By gidi in forum 5.x Legacy Premium Help
    Replies: 5
    Last Post: Jun 06, 2023, 3:07 PM
  3. Replies: 2
    Last Post: Nov 21, 2013, 3:44 AM
  4. Replies: 1
    Last Post: Jun 25, 2013, 12:14 PM
  5. Replies: 9
    Last Post: Sep 19, 2008, 11:03 AM

Posting Permissions