[CLOSED] SelectionModel.SelectAll() Not Working As Expected

  1. #1

    [CLOSED] SelectionModel.SelectAll() Not Working As Expected

    I have a page with a simple gridpanel. When the page first loads, I want all the rows in the grid to be pre-selected. In other words, I want the checkboxes to be defaulted to checked for each row.

    When I click the submit button, I want to perform a simple check to see if the user has any rows selected. If the user didn't select any rows, I want to display a message box stating that the user must select at least one row.

    What is happening in my code is:
    1. The rows are not coming in checked when the page is loaded.
    2. When the user clicks submit without selecting any rows, the warning message is not displayed. Also, as a weird side-effect, clicking the Submit button causes the all the rows to become checked. I do not understand this behavior.

    Please take a look at my sample code and help me to understand what is going on.

    Thanks.

    <%@ Page Language="vb" AutoEventWireup="false" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <script runat="server">
    
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            Dim data As New List(Of Object)
            With data
                .Add(New With {.AccountID_in = 1, .DisplayName = "Indiana Jones", .AccountNumber_vc = "1232133", .AccountType_vc = "IRA", .MarketValue = 3122312.32})
            End With
            GoodAccountsStore.DataSource = data
            GoodAccountsStore.DataBind()
            
            GoodSelectionModel.SelectAll()
    
        End Sub
        
        Public Sub SubmitButton_Click(ByVal sender As Object, ByVal e As EventArgs)
            Dim count As Integer = 0
            For Each row In CType(GoodAccountsGrid.SelectionModel.Primary, RowSelectionModel).SelectedRows
                count += 1
            Next
            If count = 0 Then
                Dim xConfig As New Ext.Net.MessageBoxConfig
                With xConfig
                    .Title = "Account Selection Error"
                    .Message = "Please select at least one account."
                    .Buttons = Ext.Net.MessageBox.Button.OK
                End With
                Ext.Net.X.Msg.Show(xConfig)
                Exit Sub
            End If
        End Sub
    </script>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <ext:ResourceManager ID="ResourceManager1" runat="server" />
        <div>
            <ext:GridPanel ID="GoodAccountsGrid" Title="Accounts Eligible for Householding" runat="server"
                Height="150" Collapsible="true" AutoExpandColumn="DisplayName">
                <Store>
                    <ext:Store ID="GoodAccountsStore" runat="server">
                        <Reader>
                            <ext:JsonReader IDProperty="AccountID_in">
                                <Fields>
                                    <ext:RecordField Name="AccountID_in">
                                    </ext:RecordField>
                                    <ext:RecordField Name="DisplayName" />
                                    <ext:RecordField Name="AccountNumber_vc" />
                                    <ext:RecordField Name="AccountType_vc" />
                                    <ext:RecordField Name="MarketValue" Type="Float" />
                                </Fields>
                            </ext:JsonReader>
                        </Reader>
                    </ext:Store>
                </Store>
                <ColumnModel ID="ColumnModel1" runat="server">
                    <Columns>
                        <ext:Column Header="Description" Width="160" DataIndex="DisplayName" />
                        <ext:Column Header="Account Number" Width="150" DataIndex="AccountNumber_vc" />
                        <ext:Column Header="Account Type" Width="150" DataIndex="AccountType_vc" />
                        <ext:Column Header="Market Value" Width="150" DataIndex="MarketValue">
                            <Renderer Format="UsMoney" />
                        </ext:Column>
                    </Columns>
                </ColumnModel>
                <SelectionModel>
                    <ext:CheckboxSelectionModel ID="GoodSelectionModel" runat="server" />
                </SelectionModel>
            </ext:GridPanel>
            <ext:Button runat="server" ID="SubmitButton" Text="Submit">
                <DirectEvents>
                    <Click OnEvent="SubmitButton_Click" />
                </DirectEvents>
            </ext:Button>
        </div>
        </form>
    </body>
    </html>
    Last edited by Daniil; Aug 15, 2011 at 3:58 PM. Reason: [CLOSED]
  2. #2
    Hi,

    There are two moments.

    1. Please use .SelectAll() during DirectEvent only. Within Page_Load I can suggest:
    Dim f As New JFunction()
    f.Handler = "this.getSelectionModel().selectAll();"
    GridPanel1.On("viewready", f)
    2. When DirectEvent occurs the common page life cycle is executed including Page_Load. So, .SelectAll() is executed when you click on the button.

    Please wrap Page_Load code in:
    If Not ExtNet.IsAjaxRequest Then
                ...
    End If
    Here is the full example.

    Example
    <%@ Page Language="vb" %>
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <script runat="server">
     
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            If Not ExtNet.IsAjaxRequest Then
                Dim data As New List(Of Object)
                With data
                    .Add(New With { _
                            .AccountID_in = 1, _
                            .DisplayName = "Indiana Jones", _ 
                            .AccountNumber_vc = "1232133", _
                            .AccountType_vc = "IRA", _
                            .MarketValue = 3122312.32 _
                        })
                End With
                Store1.DataSource = data
                Store1.DataBind()
                
                Dim f As New JFunction()
                f.Handler = "this.getSelectionModel().selectAll();"
                GridPanel1.On("viewready", f)
            End If
        End Sub
         
        Public Sub SubmitButton_Click(ByVal sender As Object, ByVal e As EventArgs)
            Dim count As Integer = 0
            For Each row In CType(CheckboxSelectionModel1, RowSelectionModel).SelectedRows
                count += 1
            Next
            If count = 0 Then
                Dim xConfig As New Ext.Net.MessageBoxConfig
                With xConfig
                    .Title = "Account Selection Error"
                    .Message = "Please select at least one account."
                    .Buttons = Ext.Net.MessageBox.Button.OK
                End With
                ExtNet.Msg.Show(xConfig)
            Else
                ExtNet.Msg.Alert("Count", count).Show()
            End If
        End Sub
    </script>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Ext.Net Example</title>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
            <ext:GridPanel 
                ID="GridPanel1" 
                Title="GridPanel" 
                runat="server"
                Height="150" 
                AutoExpandColumn="DisplayName">
                <Store>
                    <ext:Store ID="Store1" runat="server">
                        <Reader>
                            <ext:JsonReader IDProperty="AccountID_in">
                                <Fields>
                                    <ext:RecordField Name="AccountID_in" />
                                    <ext:RecordField Name="DisplayName" />
                                    <ext:RecordField Name="AccountNumber_vc" />
                                    <ext:RecordField Name="AccountType_vc" />
                                    <ext:RecordField Name="MarketValue" Type="Float" />
                                </Fields>
                            </ext:JsonReader>
                        </Reader>
                    </ext:Store>
                </Store>
                <ColumnModel runat="server">
                    <Columns>
                        <ext:Column Header="Description" Width="160" DataIndex="DisplayName" />
                        <ext:Column Header="Account Number" Width="150" DataIndex="AccountNumber_vc" />
                        <ext:Column Header="Account Type" Width="150" DataIndex="AccountType_vc" />
                        <ext:Column Header="Market Value" Width="150" DataIndex="MarketValue">
                            <Renderer Format="UsMoney" />
                        </ext:Column>
                    </Columns>
                </ColumnModel>
                <SelectionModel>
                    <ext:CheckboxSelectionModel ID="CheckboxSelectionModel1" runat="server" />
                </SelectionModel>
            </ext:GridPanel>
            <ext:Button runat="server" Text="Submit">
                <DirectEvents>
                    <Click OnEvent="SubmitButton_Click" />
                </DirectEvents>
            </ext:Button>
        </form>
    </body>
    </html>

Similar Threads

  1. Replies: 5
    Last Post: Jun 19, 2012, 9:06 PM
  2. Replies: 0
    Last Post: Feb 06, 2012, 7:29 PM
  3. [CLOSED] GridPanel local filter selectAll
    By vali1993 in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Feb 23, 2011, 6:51 PM
  4. [CLOSED] [1.0] MultiCombo Change listener not working as expected
    By jmcantrell in forum 1.x Legacy Premium Help
    Replies: 11
    Last Post: Aug 20, 2010, 3:06 PM
  5. [CLOSED] CheckboxSelectionModel selectAll
    By jwaite in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Feb 23, 2010, 8:04 PM

Posting Permissions