[CLOSED] Locked Datagrid loses selection by DataBind

  1. #1

    [CLOSED] Locked Datagrid loses selection by DataBind

    I have a new problem with locked grids.

    After the "Grid.DataBind" the grid loses the selection.

    If you comment out If i = 1 Then _Col.Locked = True again and then select a row and click on Databind , everything works. Why?

    Imports Ext.Net
    
    Public Class grid
    
        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
    
            Dim _ToolTip As New ToolTip
            _ToolTip.ID = "mwtooltip"
            _ToolTip.Target = "={#{mwgrid}.getView().el}"
            _ToolTip.Delegate = ".x-grid-cell"
            _ToolTip.TrackMouse = False
            _ToolTip.Listeners.Show.Handler = "onShow(this, #{mwgrid});"
    
            Dim _Script As String = " <script> "
            _Script &= "      var onShow = function (toolTip, grid) { "
            _Script &= "        var view = grid.getView(),"
            _Script &= "        store = grid.getStore(),"
            _Script &= "        record = view.getRecord(view.findItemByChild(toolTip.triggerElement)),"
            _Script &= "        column = view.getHeaderByCell(toolTip.triggerElement),"
            _Script &= "        data =  record.get(column.dataIndex);"
            _Script &= "        toolTip.update(data);"
            _Script &= "};"
            _Script &= "   </script>"
    
            Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "onShow", _Script)
    
            With aktGrid
    
                .ID = "mwgrid"
                .Width = 700
                .Height = 350
    
                .SelectionModel.Clear()
                .View.Clear()
                .Plugins.Clear()
                .ColumnModel.Columns.Clear()
                .Features.Clear()
                .Store.Clear()
    
                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)
    
                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(_ToolTip)
            Page.FindControl("form1").Controls.Add(_button)
    
    
        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
    Last edited by fabricio.murta; Jul 08, 2023 at 5:25 PM.
  2. #2
    Hello, @gidi!

    I've tried your test case and, besides the issue discussed in Problem with locked Column, which we already proposed a solution for, I couldn't reproduce any issue with clicking the Databind button. Can you review the test case or, maybe, be more specific on which error it triggers when locking is enabled and the button is clicked?

    Is the code in the provided test case, lines 24-33 related to the issue at all? If not, maybe it helps if unrelated code is not present in test cases. Or perhaps just applying the same fix suggested in the thread above also fixes this issue?

    Looking forward to your follow-up!
    Fabrício Murta
    Developer & Support Expert
  3. #3
    Hi Fabrício,

    The problem is that after clicking on databinding with the column locked, the selection is lost. If you uncomment the " If i = 1 Then _Col.Locked = True" line again, everything works as usual.

    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()
    
                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)
    
                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
    
                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
  4. #4
    Hello again, @Gidi!

    I've tried your new test case, still the same. No matter whether I comment out or not line 70, the selection is retained when I click the "Databind" button, if I let the page with its initial selection or if I select some other record.

    Perhaps if you provided the full test case, and not just its code behind implementation? There might be something amiss.

    Here, I've been trying your code behind sample with this vb.NET all-in-one ASPX:

    <%@ Page Language="vb" %>
    
    <!DOCTYPE html>
    
    <script runat="server">
        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()
    
                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)
    
                Dim _View As New Ext.Net.GridView
                _View.StripeRows = True
                _View.TrackOver = True
    
                .View.Add(_View)
    
            End With
    
            Dim _button As New Ext.Net.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
                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
    </script>
    <html>
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        </form>
    </body>
    </html>
    So, as you can see, just a bare minimum HTML to wrap the form1 placeholder where you seem to inject the components to. Maybe your context is different, and it may be required to avoid the issue, or simply there's something else in the page that, as unlikely as it may sound, makes the selection go only and only when locking is enabled in the grid?

    Maybe you can reproduce with some javascript code to say, like "selection: 1 row" or "selected: col1 = 9:00", so that when selection is undone the test stub says "no record selected"? Just a thought, as visually, the selection is retained on my side. Or perhaps, you're not running Ext.NET 5.3.0?

    One way or another, it looks like in this case there's something external to the code sample you shared that's causing the issue.

    Looking forward to your follow-up!
    Fabrício Murta
    Developer & Support Expert
  5. #5
    Oh man, am I stupid. I still have Ext.NET 5.2. Excuse me Fabricio.

    Thanks a lot for your help.
  6. #6
    Alright, Gidi! If you have any issues upgrading to 5.3.0, just let us know!
    Fabrício Murta
    Developer & Support Expert

Similar Threads

  1. Replies: 1
    Last Post: Jan 06, 2015, 11:18 AM
  2. Replies: 1
    Last Post: Dec 22, 2014, 1:20 PM
  3. Replies: 2
    Last Post: Nov 21, 2013, 3:44 AM
  4. Replies: 0
    Last Post: Sep 01, 2010, 8:39 PM
  5. Replies: 9
    Last Post: Sep 19, 2008, 11:03 AM

Posting Permissions