getSelectionMemory().clearMemory() does not clear SelectedRows if current page has no checked items

  1. #1

    getSelectionMemory().clearMemory() does not clear SelectedRows if current page has no checked items

    On a paged GridPanel using the checkbox selection model, the list of checked items is unreliably unchecked if we try to 'uncheck all items'. This is not possible to trigger if we have a column checkbox like in [url]https://examples2.ext.net/#/GridPanel/Selection_Models/Checkbox_Selection/[/code] but if you use an ordinary button to clear the selection, and click it having items checked on other pages only, although on screen all items are cleared, the column selection model's <i>SelectedRows</i> will keep the selections made even though you try to SelectedRows.Clear() during the 'Clear' button click event.

    The code to reproduce this issue is as follows:
    multipage_clearAll.aspx
    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="multipage_clearAll.aspx.cs" Inherits="ExtNetPlayground.multipage_clearAll" %>
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <ext:ResourceManager runat="server" />
            <ext:DropDownField runat="server" ID="ddfTag" TriggerIcon="SimpleMagnify" Editable="false" MatchFieldWidth="false" Width="600">
                <Component>
                    <ext:GridPanel runat="server" ID="gvTag" Width="600" Height="240" HideHeaders="true" MultiSelect="true">
                        <TopBar>
                            <ext:Toolbar runat="server" ID="tbTag">
                                <Items>
                                    <ext:ToolbarFill runat="server" ID="tbfTag" />
                                    <ext:Button runat="server" ID="btnOk" Icon="Accept" Width="80">
                                        <Listeners>
                                            <Click Handler="App.ddfTag.collapse();" />
                                            <AfterRender Handler="App.btnOk.setText('hai');" />
                                        </Listeners>
                                    </ext:Button>
                                    <ext:Button runat="server" ID="btnClear" Icon="ControlRemoveBlue" Width="80">
                                        <Listeners>
                                            <AfterRender Handler="App.btnClear.setText('clear');" />
                                        </Listeners>
                                        <DirectEvents>
                                            <Click OnEvent="ddfTag_ClearSelection" />
                                        </DirectEvents>
                                    </ext:Button>
                                </Items>
                            </ext:Toolbar>
                        </TopBar>
                        <Store>
                            <ext:Store ID="stoTag" runat="server" PageSize="4">
                                <Model>
                                    <ext:Model ID="mdlTag" runat="server" IDProperty="Id">
                                        <Fields>
                                            <ext:ModelField Name="Id" Type="Int" />
                                            <ext:ModelField Name="Tag" Type="String" />
                                        </Fields>
                                    </ext:Model>
                                </Model>
                            </ext:Store>
                        </Store>
                        <ColumnModel runat="server" ID="cmlTag">
                            <Columns>
                                <ext:Column runat="server" ID="coltag2" DataIndex="Tag" Flex="1" />
                            </Columns>
                        </ColumnModel>
                        <SelectionModel>
                            <ext:CheckboxSelectionModel runat="server" ID="csmTag" Mode="Multi" />
                        </SelectionModel>
                        <BottomBar>
                            <ext:PagingToolbar runat="server" ID="pgnTag" />
                        </BottomBar>
                    </ext:GridPanel>
                </Component>
                <DirectEvents>
                    <Collapse OnEvent="csmTag_SelectionChange" />
                </DirectEvents>
            </ext:DropDownField>
        </div>
        </form>
    </body>
    </html>
    multipage_clearAll.aspx.cs
    using Ext.Net;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    namespace ExtNetPlayground
    {
        public class tagType
        {
            public tagType(int i, string t)
            {
                Id = i;
                Tag = t;
            }
            public int Id { get; set; }
            public string Tag { get; set; }
        }
    
        public partial class multipage_clearAll : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                stoTag.DataSource = new List<tagType> { 
                        new tagType(1, "First entry"),
                        new tagType(2, "Second entry"),
                        new tagType(3, "Thrird entry"),
                        new tagType(4, "Fourth entry"),
                        new tagType(5, "Fifth entry"),
                        new tagType(6, "Sixth entry"),
                        new tagType(7, "Seventh entry")
                    };
                if (!X.IsAjaxRequest)
                {
    
                    btnClear.Listeners.Click.Handler = "Ext.net.Mask.show({ msg: 'Updating controls...', el: gvTag });" +
                        "App.gvTag.getSelectionMemory().clearMemory(); App.csmTag.deselectAll();";
                }
            }
    
            protected void ddfTag_ClearSelection(object sender, DirectEventArgs e)
            {
                gvTag.Element.Unmask();
            }
    
            protected void csmTag_SelectionChange(object sender, DirectEventArgs e)
            {
                var msgA = new MessageBoxConfig();
                msgA.Buttons = MessageBox.Button.OK;
                msgA.Icon = MessageBox.Icon.INFO;
                msgA.Title = "Selection Updated.";
                msgA.Message = "You have " + csmTag.SelectedRows.Count() + " items selected now.";
                X.Msg.Show(msgA);
            }
        }
    }
    To reproduce the error:
    1. Compile and run the above page
    2. Expand the box and check some items on either the first or second page. Click 'hai' (ok) button.
    3. It will show a message box telling how many items you checked.
    4. Now, re-expand the box and move to a page where you selected no entries. Click 'Clear'.
    5. The items on the other page will show unchecked. Click 'hai'/ok.
    6. The message box will still say you have the same amount of checked items, although no item is checked on the grid.


    If you click 'clear' on any page that has one or more checked items, the clearing works just fine. The only situation I can't effective clear the 'SelectedRows' list is when trying to clear a page having no currently checked items.

    Is there a workaround for this? Am I trying something wrong?
    Last edited by fabricio.murta; Sep 24, 2014 at 4:42 PM. Reason: Added 'deselectAll()' to the event.
  2. #2
    I've just "solved" this problem.

    It's a nice and extremely elegant solution (irony; workaround). Yet, logic: check a box on the current page before unchecking everything else.

    So, lines 38 and 39 becomes:
                    btnClear.Listeners.Click.Handler = "Ext.net.Mask.show({ msg: 'Updating controls...', el: gvTag });"
                        "App.csmTag.select(1); App.gvTag.getSelectionMemory().clearMemory(); App.csmTag.deselectAll();";
    I didn't expect to have a page with 0 entries though, anyway this will only happen when there's absolutely no entries thus nothing to uncheck.
    Last edited by fabricio.murta; Sep 24, 2014 at 6:33 PM. Reason: code in code tag.
  3. #3
    Hi @avenger,

    Please use:
    App.gvTag.getSelectionMemory().clearMemory();
    App.gvTag.getSelectionSubmit().updateSelection();
    App.csmTag.deselectAll();
    The updateSelection call will do the needful if no selection on the current page.

    Please do not hesitate to ask if you have any questions.
    Last edited by Daniil; Sep 25, 2014 at 3:57 PM.
  4. #4
    That really really does the trick! Thank you!

Similar Threads

  1. [CLOSED] CheckBoxGroup Items Checked from DirectEvent
    By osef in forum 2.x Legacy Premium Help
    Replies: 6
    Last Post: Apr 01, 2014, 7:26 PM
  2. [CLOSED] Get Checked items of checkbox group
    By mohan.bizbites in forum 2.x Legacy Premium Help
    Replies: 1
    Last Post: Oct 21, 2013, 5:02 PM
  3. clear checked rows after reload the grid panel
    By hongxue in forum 2.x Help
    Replies: 0
    Last Post: Jun 20, 2013, 1:38 AM
  4. Replies: 4
    Last Post: Mar 08, 2013, 4:16 PM
  5. Clear RadioGroup checked item
    By chunhuxiao in forum 1.x Help
    Replies: 0
    Last Post: Apr 26, 2012, 6:34 AM

Tags for this Thread

Posting Permissions