[OPEN] [#181] GridPanel CheckBoxSelectionModel PageProxy

  1. #1

    [OPEN] [#181] GridPanel CheckBoxSelectionModel PageProxy

    Hello,
    Thanks for your excellent job,
    I have a search control that it inherits from GridPanel. I create the store and a page proxy at run time and use an OnReadData event to read and filtering(remote mode). I use CheckBoxSelectionModel for selection model.
    I want to use a DirectMethod to delete some records and update the view after delete on server side, but the SelectionModel.Primary always return 0 in server side, also When I want to get the selected items on different pages in client side the getSelectionModel().getSelection() method returns only the selected items on the active page.
    How can I get the Selected Items in this case in the server side?

    Regards
    Corey
    Last edited by Daniil; Apr 01, 2013 at 6:24 AM. Reason: [OPEN] [#181]
  2. #2
    Hello!

    Welcome to our forum!

    You should send selected values received using getSelectionModel().getSelection() to your DirectMethod as a parameter.

    Post moved to 2.x Help. Please, review the following threads:

    http://forums.ext.net/showthread.php?3440
    http://forums.ext.net/showthread.php?10205
    Last edited by Baidaly; Mar 26, 2013 at 10:57 PM.
  3. #3
    I send the selected items to my DirectMethods, I'm using remote paging, getSelectionModel().getSelection() returns only the selected items on the active page, it doesn't return all selected items on all pages. How can i get all selected items on all pages in client side?
  4. #4
    Hi Corey,

    Yes, commonly a SelectionModel doesn't maintain selection across pages.

    But there is a SelectionMemory plugin to do that. To enable it records must have explicit ids. It means that a Model must have IDProperty or an "id" field in the data which you populated into the Store (IDProperty is "id" by default).

    Example
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <%@ Import Namespace="System.Collections.Generic" %>
    
    <script runat="server">
        public List<object> MyData = new List<object> 
        { 
            new { test = "test1" },
            new { test = "test2" },
            new { test = "test3" },
            new { test = "test4" },
            new { test = "test5" },
            new { test = "test6" },
            new { test = "test7" },
            new { test = "test8" },
            new { test = "test9" }
        };
    
        protected void Store_ReadData(object sender, StoreReadDataEventArgs e)
        {
            List<object> data = this.MyData;
            var limit = e.Limit;
            if ((e.Start + e.Limit) > data.Count)
            {
                limit = data.Count - e.Start;
            }
            List<object> rangeData = (e.Start < 0 || limit < 0) ? data : data.GetRange(e.Start, limit);
            e.Total = data.Count;
            (sender as Store).DataSource = rangeData;
        }
    
        protected void GetCount(object sender, DirectEventArgs e)
        {
            X.Msg.Alert("GetCount", (this.GridPanel1.GetSelectionModel() as RowSelectionModel).SelectedRows.Count).Show();
        }
    </script>
    
    <!DOCTYPE html>
    
    <html>
    <head runat="server">
        <title>Ext.NET v2 Example</title>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
            <ext:GridPanel ID="GridPanel1" runat="server">
                <Store>
                    <ext:Store runat="server" OnReadData="Store_ReadData" PageSize="3">
                        <Model>
                            <ext:Model runat="server" IDProperty="test">
                                <Fields>
                                    <ext:ModelField Name="test" />
                                </Fields>
                            </ext:Model>
                        </Model>
                        <Proxy>
                            <ext:PageProxy>
                                <Reader>
                                    <ext:JsonReader />
                                </Reader>
                            </ext:PageProxy>
                        </Proxy>
                    </ext:Store>
                </Store>
                <ColumnModel runat="server">
                    <Columns>
                        <ext:Column runat="server" Text="Test" DataIndex="test" />
                    </Columns>
                </ColumnModel>
                <BottomBar>
                    <ext:PagingToolbar runat="server" />
                </BottomBar>
                <SelectionModel>
                    <ext:RowSelectionModel runat="server" />
                </SelectionModel>
            </ext:GridPanel>
            <ext:Button runat="server" Text="How many selected rows?" OnDirectClick="GetCount" />
        </form>
    </body>
    </html>
    SelectionModel.Primary always return 0 in server side
    Please provide a test case to reproduce.
  5. #5
    Hi Daniil,
    Thanks for your response, I set the IDProperty and The SelectionMemory and SelectionSubmit are active.
    To produce the bug
    1- A client side grid that it's inherited from Ext.grid.Panel with no overriden methods, just some simple methods are added.
    2- A control that it's inherited from GridPanel with overriden XType and InstanceOf and Resources for client side grid and in OnLoad method of inherited control I build the Model, Store , PageProxy,CheckBoxSelectionRowModel and ColumnModel for grid.
    3- create an user control that contains an instance of grid.
    4-create a page that contains the user control.

    1-Grid.js
    Ext.define('Test.Ux.Grid.MyGrid', {
        extend: 'Ext.grid.Panel',
        alias: 'widget.mygrid',
    
        refresh: function() {
            var me = this, store = me.getStore();
            store.load({ callback: function() { me.getView().refresh(); } });
        },
        onSelectionChange: function (s, selected) {
            var hasSelected = selected && selected.length > 0;
            var editBtn = this.down("#GetC");
            if (editBtn) editBtn.setDisabled(!hasSelected);
            
        },
        showCount : function() {
            Test[this.id].ShowCount();
        },
    });
    2.My Grid
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using Ext.Net;
    
    namespace SelectionGridTest.Grid
    {
    
        public class MyGrid : GridPanel
        {
           
            public override string InstanceOf
            {
                get { return "Test.Ux.Grid.MyGrid"; }
            }
    
            public override string XType
            {
                get { return "mygrid"; }
            }
            protected override void OnLoad(EventArgs e)
            {
              
                Frame = true;
                Title = "Test";
                Layout = "Fit";
                Region = Region.Center;
                ColumnLines = true;
                TabMenuHidden = true;
                Height = 500;
                var store = new Store
                {
                    ID = ID + "St",
                    PageSize = 3,
                    AutoLoad = false,
                    RemoteSort = true,
                    RemoteFilter = true,
                    IsPagingStore = true,
                    RemoteGroup = true,
                    RemotePaging = true,
                    
                    Model = { new Model()
                                  {
                                      ID = ID+"Mdl",
                                      IDProperty = "test",
                                      Fields = {new ModelField("test", ModelFieldType.Auto)}
                                  }
                    },
                    Proxy = { new PageProxy(){IDParam="prx"} },
                };
    
                //IsPagingStore ??
               // store.CustomConfig.Add(new ConfigItem("isPagingStore", "true", ParameterMode.Raw));
                store.ReadData += Store_ReadData;
                Bin.Add(store);
                StoreID = store.ID;
                View.Add(new Ext.Net.GridView
                               {
                                   ID = ID + "Vw",
                                   StripeRows = true,
                               });
    
                //
                ColumnModel.Columns.Add(new Column() {ID = "col1", DataIndex = "test", Text = "Test" });
                SelectionModel.Add(new CheckboxSelectionModel() {ID ="csm", CheckOnly = true,PruneRemoved = false,Mode = SelectionMode.Multi});
    
    
                var cButton = new Button("Get Count");
                cButton.ID = "GetC";
                cButton.Disabled = true;
                cButton.Listeners.Click.Handler = "item.up('grid').showCount();";
               // cButton.DirectEvents.Click.Event += GetCount;
                TopBar.Add(new Toolbar()
                               {
                                   ID = "TLb",
                                   Items = {new Button("Refresh","item.up('grid').refresh();"){ID = "Refb"},
                                       cButton}
                               });
                BottomBar.Add(new PagingToolbar() { ID = "PP"});
                RegisterDirectMethods();
                if (!Ext.Net.X.IsAjaxRequest)
                {
                    CustomConfig.Add(new ConfigItem("formControl", "test", ParameterMode.Value));
                    Listeners.SelectionChange.Handler = "this.onSelectionChange(this, selected);";
                }
                 var filterMenu = new GridFilters { ID = ID+"F" + "Mnfil", AutoReload = false};
                 filterMenu.Filters.Add(new StringFilter() { DataIndex = "test" });
                Features.Add(filterMenu);
                
            }
    
            public List<object> MyData = new List<object>
        {
            new { test = "test1" },
            new { test = "test2" },
            new { test = "test3" },
            new { test = "test4" },
            new { test = "test5" },
            new { test = "test6" },
            new { test = "test7" },
            new { test = "test8" },
            new { test = "test9" }
        };
            private void RegisterDirectMethods()
            {
    
                ResourceManager.DirectMethodNamespace = "Test";
                ResourceManager.AddDirectMethodControl(this);
            }
            protected void Store_ReadData(object sender, StoreReadDataEventArgs e)
            {
               
                List<object> data = this.MyData;
                var limit = e.Limit;
                if ((e.Start + e.Limit) > data.Count)
                {
                    limit = data.Count - e.Start;
                }
                List<object> rangeData = (e.Start < 0 || limit < 0) ? data : data.GetRange(e.Start, limit);
                e.Total = data.Count;
                (sender as Store).DataSource = rangeData;
                 (sender as Store).DataBind();
            }
            [DirectMethod()]
            public void ShowCount()
            {
                Ext.Net.X.Msg.Alert("GetCount", (GetSelectionModel() as RowSelectionModel).SelectedRows.Count).Show();
            }
            protected void GetCount(object sender, DirectEventArgs e)
            {
                Ext.Net.X.Msg.Alert("GetCount", (GetSelectionModel() as RowSelectionModel).SelectedRows.Count).Show();
            }
    
            protected override List<ResourceItem> Resources
            {
                get
                {
                    var resources = base.Resources;
                    resources.Capacity += 1;
                    resources.Add(new ClientScriptItem(typeof(MyGrid), "SelectionGridTest.Resources.MyGrid.js", ""));
                    
                    return resources;
                }
            }
        }
    }
    3.TestUC User Control
    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="TestUC.ascx.cs" Inherits="SelectionGridTest.TestUC" %>
    <%@ Register TagPrefix="ext" Namespace="SelectionGridTest.Grid" Assembly="SelectionGridTest" %>
    <ext:MyGrid ID="grd" runat="server"></ext:MyGrid>
    4.TestPage.aspx
    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Test.aspx.cs" Inherits="SelectionGridTest.Test" %>
    <%@ Register TagPrefix="ext" Namespace="Ext.Net" Assembly="Ext.Net, Version=2.1.1.18167, Culture=neutral, PublicKeyToken=2e12ce3d0176cd87" %>
    <%@ Register TagPrefix="ext" Namespace="SelectionGridTest.Grid" Assembly="SelectionGridTest" %>
    <%@ Register Src="~/TestUC.ascx" TagPrefix="uc1" TagName="TestUC" %>
    
    
    <!DOCTYPE html>
    
    <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>
            <uc1:TestUC runat="server" id="TestUC" />
        </div>
        </form>
    </body>
    </html>

    The custom control works fine but when i use the custom grid in an user control it doesn't work.
    You can find the sample code to produce the problem.

    Regards,
    Corey
    Last edited by Corey Fazel; Mar 27, 2013 at 7:27 PM.
  6. #6
    Thank you. I reproduced the problem. We will investigate.
  7. #7
    Quote Originally Posted by Daniil View Post
    Thank you. I reproduced the problem. We will investigate.
    I've resolved the problem. IXPostBackDataHandler restores the selection data before OnLoad event. So I moved the creation of RowSelectionModel to OnInit event and it works fine now. So you can close this thread.
  8. #8
    Yes, the problem is with LoadPostData.

    It is good to know that creating a SelectionModel in Page_Init instead of Page_Load helps. Thank you for the update.

    Though we are investigating a fix to get it working for Page_Load as well.
  9. #9
    Moved to the Bugs forum and created an Issue.
    https://github.com/extnet/Ext.NET/issues/181

Similar Threads

  1. GridPanel CheckboxSelectionModel
    By winner0819 in forum 1.x Help
    Replies: 2
    Last Post: Dec 12, 2011, 3:00 AM
  2. GridPanel Paging with PageProxy
    By jigpatel06 in forum 1.x Help
    Replies: 3
    Last Post: Mar 11, 2011, 10:33 AM
  3. Exception PageProxy in gridpanel row expander
    By 78fede78 in forum 1.x Help
    Replies: 1
    Last Post: Jul 15, 2010, 10:44 AM
  4. Exception PageProxy in gridpanel
    By 78fede78 in forum 1.x Help
    Replies: 1
    Last Post: Jul 02, 2010, 12:50 PM
  5. Add pageproxy at runtime
    By 78fede78 in forum 1.x Help
    Replies: 0
    Last Post: Jun 30, 2010, 3:20 PM

Posting Permissions