[CLOSED] Infinite Scrolling / onReadData / everything from code behind

  1. #1

    [CLOSED] Infinite Scrolling / onReadData / everything from code behind

    Hi

    I am trying to create an infinite scrolling gridpanel from code behind. Now I have some troubles with the OnReadData. It doesn't exist. What do I have to do? Tried some stuff with different proxies but nothing worked out so far....

    In the end I would love to combine it with the a remote grid filter. Is this even possible?


    Thanks for any input.

    best regards.
    Last edited by Daniil; Oct 08, 2013 at 6:49 AM. Reason: [CLOSED]
  2. #2
    Hi @tMp,

    Quote Originally Posted by tMp View Post
    Now I have some troubles with the OnReadData. It doesn't exist.
    I guess the Store doesn't exist, does it? Do you mean a server side exception when a PageProxy request occurs?

    A PageProxy uses a Store's OnReadData event handler. The OnReadData event is a DirectEvent. As any DirectEvent it requires a control instance (a Store one in your case) on server when a request occurs. Since you create the Store dynamically, I guess you don't recreate it during each request.

    There are two options.

    1. Recreate the Store during each request.

    or

    2. Deny from a PageProxy and use an AjaxProxy referring to, for example, an HTTP handler (ashx).

    Quote Originally Posted by tMp View Post
    In the end I would love to combine it with the a remote grid filter. Is this even possible?
    Yes, it should be possible.
  3. #3
    @Daniil,

    your are one step ahead of me ;)

    My problem is:
    OnReadData="Store_ReadData"
    in mark up. What is the equivalent in code behind because it doesn't exist when I try to create the store.
  4. #4
    Sorry, I misunderstood the question.

    Here you are.
    Store store = new Store();
    store.ReadData += Store_ReadData;
    It is for C#.
  5. #5
    @Daniil

    somehow I must be completely off....

    Here is my demo code:
    <%@ Page Language="C#" %>
     
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
     
    <!DOCTYPE html>
     
    <script runat="server">
     
        // on page load
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                Window win = createTaskListWindow();
    
                win.Render(this.form);
            }
        }
    
        protected void store_ReadData(object sender, StoreReadDataEventArgs e)
        {
            //Store store = (Store)sender;
            Store store = X.GetCmp<Store>("STORE_LIST");
    
            Model model = new Model
            {
                Fields = {
                    new ModelField { Name = "ID", Type = ModelFieldType.Int },
                    new ModelField { Name = "NUMBER", Type = ModelFieldType.Int }
                }
            };
            store.Model.Add(model);
            
            int start = e.Start, limit = e.Start;
    
            System.Data.DataTable dt = new System.Data.DataTable();
            dt.Columns.Add("ID", typeof(int));
            dt.Columns.Add("NUMBER", typeof(int));
            
            Random random = new Random();
    
            for (int i = start + 1; i <= start + limit; i++)
            {
                dt.Rows.Add(i, random.Next(0, 10000));
            }
    
            store.DataSource = dt;
            store.DataBind();
            e.Total = 5000;
        }
        
        protected Window createTaskListWindow()
        {
            Store store = new Store
            {
                ID = "STORE_LIST",
                Buffered = true,
                PageSize = 200,
                TrailingBufferZone = 10,
                LeadingBufferZone = 10,
                Proxy = { new PageProxy {  } },
                Model = {
                    new Model {
                        Fields = {
                            new ModelField { Name = "ID", Type = ModelFieldType.Int },
                            new ModelField { Name = "NUMBER", Type = ModelFieldType.Int }
                        }
                    }
                }
            };
            store.ReadData += store_ReadData;
    
            Window win = new Window
            {
                ID = "wList",
                Title = "Demo",
                Width = 812,
                ManageHeight = true,
                Items =
                {
                    new GridPanel {
                        ID = "gpList",
                        Height = 800,
                        Store = { store },
                        ColumnModel = {
                            Columns = {
                                new Column { DataIndex = "ID", Text = "ID", Width = 50 },
                                new Column { DataIndex = "NUMBER", Text = "Random Number", Flex = 1 }
                            }
                        }
                    }
                }
            };
    
            return win;
        }
     
    </script>
     
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title>datefield demo</title>
    </head>
    <body>
        <form id="form" runat="server">
            <ext:ResourceManager ID="ResourceManager" runat="server" />
        <div>
    
        </div>
        </form>
    </body>
    </html>
    Is the PageProxy correct for DataTables and what reader do I need? If I run this I get an error like "The control with ID 'STORE_LIST' not found".
  6. #6
    Well, it is exactly I talked about here.

    Quote Originally Posted by Daniil View Post
    I guess the Store doesn't exist, does it? Do you mean a server side exception when a PageProxy request occurs?

    A PageProxy uses a Store's OnReadData event handler. The OnReadData event is a DirectEvent. As any DirectEvent it requires a control instance (a Store one in your case) on server when a request occurs. Since you create the Store dynamically, I guess you don't recreate it during each request.

    There are two options.

    1. Recreate the Store during each request.

    or

    2. Deny from a PageProxy and use an AjaxProxy referring to, for example, an HTTP handler (ashx).
    Also please use the Render method during DirectEvents/DirectMethods only.
    win.Render(this.form);
    During Page_Load please do this way:
    this.form.Controls.Add(win);
  7. #7
    Sorry, about the rendering-thing. That was a copy & paste error from my real scenario to the demo case.

    For the recreation of the store, as I am going with version a. What I am doing wrong? As you told me in an earlier answer I am recreating the whole model of the store during each on "store_ReadData". I even tried it with reacreating the whole store but I still get the same error. Is is because the proxy has no reader? If so, what reader do I need for a DataTable? I am sorry, my brain seems to be caught in a loop.... :(

    Thanks for your help.
  8. #8
    It is too late to recreate the Store within its OnReadData handler. The OnReadData handler requires a Store instance before its execution.

    You can recreate the Store within the Page_Load.
  9. #9
    @Daniil

    Aaah, now I got the difference between the DirectEvent (always create it on page load) and the DirectMethod (only create it during call). Thanks!

    In this case I will be avoiding DirectEvents for me because I don't see the sense in loading all this stuff on every page load just in case a user presses a button that to open a window that uses a DirectEvent. I will see if the buffered version suits my purpose better.
  10. #10
    Quote Originally Posted by tMp View Post
    Aaah, now I got the difference between the DirectEvent (always create it on page load) and the DirectMethod (only create it during call). Thanks!
    Yes, a page's DirectMethod doesn't require a control instance on server.

    In this case I will be avoiding DirectEvents for me because I don't see the sense in loading all this stuff on every page load just in case a user presses a button that to open a window that uses a DirectEvent.
    Yes, it definitely makes sense.

Similar Threads

  1. [CLOSED] MVC Infinite Scrolling with GridPanel
    By leonardm in forum 2.x Legacy Premium Help
    Replies: 2
    Last Post: Aug 01, 2013, 4:00 AM
  2. Example of infinite scrolling without using proxy
    By yash.kapoor in forum 2.x Help
    Replies: 2
    Last Post: Jan 02, 2013, 7:12 AM
  3. [CLOSED] TreePanel infinite scrolling
    By Leonid_Veriga in forum 2.x Legacy Premium Help
    Replies: 1
    Last Post: Nov 06, 2012, 5:13 PM
  4. Replies: 3
    Last Post: Oct 16, 2012, 5:03 PM
  5. [CLOSED] Infinite Scrolling with MVC
    By RCN in forum 2.x Legacy Premium Help
    Replies: 14
    Last Post: Apr 12, 2012, 6:27 PM

Tags for this Thread

Posting Permissions