[CLOSED] how to pass custom parameters to the PageProxy so that in OnReadData event handler can get the parameters

  1. #1

    [CLOSED] how to pass custom parameters to the PageProxy so that in OnReadData event handler can get the parameters

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm13.aspx.cs" Inherits="TobrosCWT.test.WebForm13" %>
    
    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title></title>
        <script runat="server">
            protected void Page_Load(object sender, EventArgs e)
            {
    
            }
            public class Student
            {
                public int id { get; set; }
                public string name { get; set; }
                public int age { get; set; }
    
                public List<Student> AllStudent(int start, int limit, out int total, int age1, int age2)
                {
                    var ll = new List<Student>
                        {
                            new Student{id = 1,name = "s1",age = 7},
                            new Student{id = 2,name = "s2",age = 8},
                            new Student{id = 3,name = "s3",age = 9},
                            new Student{id = 4,name = "s4",age = 10},
                            new Student{id = 5,name = "s5",age = 11},
                            new Student{id = 6,name = "s6",age = 12},
                            new Student{id = 7,name = "s7",age = 13},
                            new Student{id = 8,name = "s8",age = 14},
                            new Student{id = 9,name = "s9",age = 15},
                            new Student{id = 10,name = "s10",age = 16},
                            new Student{id = 11,name = "s11",age = 17},
                            new Student{id = 12,name = "s12",age = 18},
                            new Student{id = 13,name = "s13",age = 19},
                            new Student{id = 14,name = "s14",age = 20}
                        };
                    total = ll.Count;
                    var rtnll = new List<Student>();
                    foreach (var l in ll)
                    {
                        if (l.id > start && l.id <= (start + limit))
                        {
                            if (age1 != 0 && age2 != 0)
                            {
                                if (l.age >= age1 && l.age <= age2)
                                {
    
                                    rtnll.Add(l);
                                }
                            }
                            else
                            { 
                                rtnll.Add(l);
                            }
                        }
                    }
                    return rtnll;
                }
            }
    
            protected void LoadData(object sender, StoreReadDataEventArgs e)
            {
                int start = e.Start;
                int limit = e.Limit;
                int total = 0;
                int age1 = 0;
                int age2 = 0;
                var ll = new Student().AllStudent(start, limit, out total, age1, age2);
                e.Total = total;
                store1.DataSource = ll;
    
                store1.DataBind();
            }
            protected void Search(object sender, EventArgs e)
            {
                int age1 = int.Parse(nf_age1.Text);
                int age2 = int.Parse(nf_age2.Text);
                // how to pass the two parameters age1 and age2 to the PageProxy so that LoadData can get the parameter
    
            }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
            <ext:ResourceManager runat="server"></ext:ResourceManager>
            <ext:GridPanel runat="server" Title="学生信息查询">
                <TopBar>
    
                    <ext:Toolbar runat="server">
                        <Items>
                            <ext:FieldContainer ID="FieldContainer1" runat="server" FieldLabel="年龄" Layout="HBoxLayout">
                                <Items>
                                    <ext:NumberField ID="nf_age1"  Text="9" runat="server"></ext:NumberField>
                                    <ext:DisplayField ID="DisplayField1"   runat="server" Text="-"></ext:DisplayField>
                                    <ext:NumberField runat="server" ID="nf_age2" Text="19"></ext:NumberField>
                                    <ext:Button ID="Button1" runat="server" Text="查询">
                                        <DirectEvents>
                                            <Click OnEvent="Search"></Click>
                                        </DirectEvents>
                                    </ext:Button>
                                </Items>
    
                            </ext:FieldContainer>
                        </Items>
    
                    </ext:Toolbar>
    
                </TopBar>
                <Store>
                    <ext:Store runat="server" ID="store1" OnReadData="LoadData" PageSize="3">
                        <Model>
                            <ext:Model runat="server">
                                <Fields>
                                    <ext:ModelField Name="id"></ext:ModelField>
                                    <ext:ModelField Name="name"></ext:ModelField>
                                    <ext:ModelField Name="age"></ext:ModelField>
                                </Fields>
                            </ext:Model>
                        </Model>
                        <Proxy>
                            <ext:PageProxy> 
                            </ext:PageProxy>
                        </Proxy>
                    </ext:Store>
    
                </Store>
    
                <ColumnModel>
                    <Columns>
                        <ext:Column runat="server" DataIndex="id" Text="编号"></ext:Column>
                        <ext:Column runat="server" DataIndex="name" Text="名称"></ext:Column>
                        <ext:Column runat="server" DataIndex="age" Text="年龄"></ext:Column>
                    </Columns>
                </ColumnModel>
                <BottomBar>
                    <ext:Toolbar ID="Toolbar1" runat="server">
                        <Items>
                            <ext:PagingToolbar ID="PagingToolbar1" runat="server" StoreID="store1"></ext:PagingToolbar>
                        </Items>
                    </ext:Toolbar>
                </BottomBar>
            </ext:GridPanel>
        </form>
    </body>
    </html>
    Last edited by Daniil; Oct 04, 2013 at 6:48 AM. Reason: [CLOSED]
  2. #2
    Hi @tobros,

    This way:

    1. Define this for the Store.
    <Parameters>
        <ext:StoreParameter Name="testParam" Value="testValue" Mode="Value" Action="read" />
    </Parameters>
    2. Get access to this parameter in the OnReadData handler.
    e.Parameters["testParam"]
  3. #3
    Quote Originally Posted by Daniil View Post
    Hi @tobros,

    This way:

    1. Define this for the Store.
    <Parameters>
        <ext:StoreParameter Name="testParam" Value="testValue" Mode="Value" Action="read" />
    </Parameters>
    2. Get access to this parameter in the OnReadData handler.
    e.Parameters["testParam"]
    i try to set parameter in Search handler,but failed.
    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm13.aspx.cs" Inherits="TobrosCWT.test.WebForm13" %>
    
    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title></title>
        <script runat="server">
            protected void Page_Load(object sender, EventArgs e)
            {
    
            }
            public class Student
            {
                public int id { get; set; }
                public string name { get; set; }
                public int age { get; set; }
    
                public List<Student> AllStudent(int start, int limit, out int total, int age1, int age2)
                {
                    var ll = new List<Student>
                        {
                            new Student{id = 1,name = "s1",age = 7},
                            new Student{id = 2,name = "s2",age = 8},
                            new Student{id = 3,name = "s3",age = 9},
                            new Student{id = 4,name = "s4",age = 10},
                            new Student{id = 5,name = "s5",age = 11},
                            new Student{id = 6,name = "s6",age = 12},
                            new Student{id = 7,name = "s7",age = 13},
                            new Student{id = 8,name = "s8",age = 14},
                            new Student{id = 9,name = "s9",age = 15},
                            new Student{id = 10,name = "s10",age = 16},
                            new Student{id = 11,name = "s11",age = 17},
                            new Student{id = 12,name = "s12",age = 18},
                            new Student{id = 13,name = "s13",age = 19},
                            new Student{id = 14,name = "s14",age = 20}
                        };
                    total = ll.Count;
                    var rtnll = new List<Student>();
                    foreach (var l in ll)
                    {
                        if (l.id > start && l.id <= (start + limit))
                        {
                            if (age1 != 0 && age2 != 0)
                            {
                                if (l.age >= age1 && l.age <= age2)
                                {
                                    rtnll.Add(l);
                                }
                            }
                            else
                            {
                                rtnll.Add(l);
                            }
                        }
                    }
                    return rtnll;
                }
            }
    
            protected void LoadData(object sender, StoreReadDataEventArgs e)
            {
                int start = e.Start;
                int limit = e.Limit;
                int total = 0;
                int age1 = int.Parse(e.Parameters["age1"]);//but here is 0 always , why?
                int age2 = int.Parse(e.Parameters["age2"]);
                var ll = new Student().AllStudent(start, limit, out total, age1, age2);
                e.Total = total;
                store1.DataSource = ll;
    
                store1.DataBind();
            }
            protected void Search(object sender, EventArgs e)
            {
                int age1 = (int)nf_age1.Number;// int.Parse(nf_age1.Text);
                int age2 = (int)nf_age2.Number;// int.Parse(nf_age2.Text);
                // how to pass the two parameters age1 and age2 to the PageProxy so that LoadData can get the parameter
                store1.Parameters["age1"] = age1.ToString();// pass value to parameter,
                store1.Parameters["age2"] = age2.ToString();
                store1.Reload();
    
            }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
            <ext:ResourceManager runat="server"></ext:ResourceManager>
            <ext:GridPanel runat="server" Title="学生信息查询">
                <TopBar>
    
                    <ext:Toolbar runat="server">
                        <Items>
                            <ext:FieldContainer ID="FieldContainer1" runat="server" FieldLabel="年龄" Layout="HBoxLayout">
                                <Items>
                                    <ext:NumberField ID="nf_age1" Text="9" runat="server"></ext:NumberField>
                                    <ext:DisplayField ID="DisplayField1" runat="server" Text="-"></ext:DisplayField>
                                    <ext:NumberField runat="server" ID="nf_age2" Text="19"></ext:NumberField>
                                    <ext:Button ID="Button1" runat="server" Text="查询">
                                        <DirectEvents>
                                            <Click OnEvent="Search"></Click>
                                        </DirectEvents>
                                    </ext:Button>
                                </Items>
    
                            </ext:FieldContainer>
                        </Items>
    
                    </ext:Toolbar>
    
                </TopBar>
                <Store>
                    <ext:Store runat="server" ID="store1" OnReadData="LoadData" PageSize="3">
                        <Model>
                            <ext:Model runat="server">
                                <Fields>
                                    <ext:ModelField Name="id"></ext:ModelField>
                                    <ext:ModelField Name="name"></ext:ModelField>
                                    <ext:ModelField Name="age"></ext:ModelField>
                                </Fields>
                            </ext:Model>
                        </Model>
                        <Proxy>
                            <ext:PageProxy>
                            </ext:PageProxy>
                        </Proxy>
                        <Parameters>
                            <ext:StoreParameter Name="age1" Value="0" Mode="Value" />
                            <ext:StoreParameter Name="age2" Value="0" Mode="Value" />
                        </Parameters>
                    </ext:Store>
    
                </Store>
    
                <ColumnModel>
                    <Columns>
                        <ext:Column runat="server" DataIndex="id" Text="编号"></ext:Column>
                        <ext:Column runat="server" DataIndex="name" Text="名称"></ext:Column>
                        <ext:Column runat="server" DataIndex="age" Text="年龄"></ext:Column>
                    </Columns>
                </ColumnModel>
                <BottomBar>
                    <ext:Toolbar ID="Toolbar1" runat="server">
                        <Items>
                            <ext:PagingToolbar ID="PagingToolbar1" runat="server" StoreID="store1"></ext:PagingToolbar>
                        </Items>
                    </ext:Toolbar>
                </BottomBar>
            </ext:GridPanel>
        </form>
    </body>
    </html>
  4. #4
    I try to replace directevent with listner
    <script type="text/javascript">
            var s = function () { 
                var a1 = Ext.getCmp("nf_age1").getValue();
                var a2 = Ext.getCmp("nf_age2").getValue(); 
              //  #{store1}.setParameter("age1", a1);   //what's the right way to do this?
             //   #{store1}.setParameter("age2", a2);
              //  #{store1}.reload();
            }
        </script>
    <ext:NumberField ID="nf_age1" Number="19" runat="server"></ext:NumberField>
                                    <ext:DisplayField ID="DisplayField1" runat="server" Text="-"></ext:DisplayField>
                                    <ext:NumberField runat="server" ID="nf_age2" Number="19" ></ext:NumberField>
                                    <ext:Button ID="Button1" runat="server" Text="查询">
                                        <Listeners>
                                            <Click Fn="s"></Click>
                                        </Listeners>
                                    </ext:Button>
  5. #5
    Setting up a Store's Parameters doesn't affect if that Store is already rendered to client. It happens in your case.

    As for the reload method. Here is a way to pass parameters.
    store.reload({
        params: {
            age1: 10,
            age2: 20
        }
    });
  6. #6
    Quote Originally Posted by Daniil View Post
    Setting up a Store's Parameters doesn't affect if that Store is already rendered to client. It happens in your case.

    As for the reload method. Here is a way to pass parameters.
    store.reload({
        params: {
            age1: 10,
            age2: 20
        }
    });
    i try the code ,but age1 and age2 are always 0 in LoadData function.
    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm13.aspx.cs" Inherits="TobrosCWT.test.WebForm13" %>
    
    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title></title>
        <script runat="server">
            protected void Page_Load(object sender, EventArgs e)
            {
    
            }
            public class Student
            {
                public int id { get; set; }
                public string name { get; set; }
                public int age { get; set; }
    
                public List<Student> AllStudent(int start, int limit, out int total, int age1, int age2)
                {
                    var ll = new List<Student>
                        {
                            new Student{id = 1,name = "s1",age = 7},
                            new Student{id = 2,name = "s2",age = 8},
                            new Student{id = 3,name = "s3",age = 9},
                            new Student{id = 4,name = "s4",age = 10},
                            new Student{id = 5,name = "s5",age = 11},
                            new Student{id = 6,name = "s6",age = 12},
                            new Student{id = 7,name = "s7",age = 13},
                            new Student{id = 8,name = "s8",age = 14},
                            new Student{id = 9,name = "s9",age = 15},
                            new Student{id = 10,name = "s10",age = 16},
                            new Student{id = 11,name = "s11",age = 17},
                            new Student{id = 12,name = "s12",age = 18},
                            new Student{id = 13,name = "s13",age = 19},
                            new Student{id = 14,name = "s14",age = 20}
                        };
                    total = ll.Count;
                    var rtnll = new List<Student>();
                    foreach (var l in ll)
                    {
                        if (l.id > start && l.id <= (start + limit))
                        {
                            if (age1 != 0 && age2 != 0)
                            {
                                if (l.age >= age1 && l.age <= age2)
                                {
                                    rtnll.Add(l);
                                }
                            }
                            else
                            {
                                rtnll.Add(l);
                            }
                        }
                    }
                    return rtnll;
                }
            }
    
            protected void LoadData(object sender, StoreReadDataEventArgs e)
            {
                int start = e.Start;
                int limit = e.Limit;
                int total = 0;
                int age1 = int.Parse(e.Parameters["age1"]);
                int age2 = int.Parse(e.Parameters["age2"]);
                var ll = new Student().AllStudent(start, limit, out total, age1, age2);
                e.Total = total;
                store1.DataSource = ll;
    
                store1.DataBind();
            }
            protected void Search(object sender, EventArgs e)
            {
                int age1 = (int)nf_age1.Number;// int.Parse(nf_age1.Text);
                int age2 = (int)nf_age2.Number;// int.Parse(nf_age2.Text);
                // how to pass the two parameters age1 and age2 to the PageProxy so that LoadData can get the parameter
                //  store1.Parameters["age1"] = age1.ToString();
                //  store1.Parameters["age2"] = age2.ToString();
    
                 
            }
        </script>
        <script type="text/javascript">
            var s = function () {
                var a1 = Ext.getCmp("nf_age1").getValue();
                var a2 = Ext.getCmp("nf_age2").getValue(); 
                App.store1.reload({
                    params: {
                        age1: a1,
                        age2: a2
                    }
                });
            }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
            <ext:ResourceManager runat="server" SourceFormatting="True"></ext:ResourceManager>
            <ext:GridPanel runat="server" Title="学生信息查询" ID="w_s">
                <TopBar>
    
                    <ext:Toolbar runat="server">
                        <Items>
                            <ext:FieldContainer ID="FieldContainer1" runat="server" FieldLabel="年龄" Layout="HBoxLayout">
                                <Items>
                                    <ext:NumberField ID="nf_age1" Number="9" runat="server"></ext:NumberField>
                                    <ext:DisplayField ID="DisplayField1" runat="server" Text="-"></ext:DisplayField>
                                    <ext:NumberField runat="server" ID="nf_age2" Number="19"></ext:NumberField>
                                    <ext:Button ID="Button1" runat="server" Text="查询">
                                        <Listeners>
                                            <Click Fn="s"></Click>
                                        </Listeners>
                                    </ext:Button>
                                </Items>
    
                            </ext:FieldContainer>
                        </Items>
    
                    </ext:Toolbar>
    
                </TopBar>
                <Store>
                    <ext:Store runat="server" ID="store1" OnReadData="LoadData" PageSize="3">
                        <Model>
                            <ext:Model runat="server">
                                <Fields>
                                    <ext:ModelField Name="id"></ext:ModelField>
                                    <ext:ModelField Name="name"></ext:ModelField>
                                    <ext:ModelField Name="age"></ext:ModelField>
                                </Fields>
                            </ext:Model>
                        </Model>
                        <Proxy>
                            <ext:PageProxy>
                            </ext:PageProxy>
                        </Proxy>
                        <Parameters>
                            <ext:StoreParameter Name="age1" Value="0" Mode="Value" />
                            <ext:StoreParameter Name="age2" Value="0" Mode="Value" />
                        </Parameters>
                    </ext:Store>
    
                </Store>
    
                <ColumnModel>
                    <Columns>
                        <ext:Column runat="server" DataIndex="id" Text="编号"></ext:Column>
                        <ext:Column runat="server" DataIndex="name" Text="名称"></ext:Column>
                        <ext:Column runat="server" DataIndex="age" Text="年龄"></ext:Column>
                    </Columns>
                </ColumnModel>
                <BottomBar>
                    <ext:Toolbar ID="Toolbar1" runat="server">
                        <Items>
                            <ext:PagingToolbar ID="PagingToolbar1" runat="server" StoreID="store1"></ext:PagingToolbar>
                        </Items>
                    </ext:Toolbar>
                </BottomBar>
            </ext:GridPanel>
        </form>
    </body>
    </html>
  7. #7
    Please set up
    ApplyMode="IfNotExists"
    for the StoreParameters.

Similar Threads

  1. Replies: 1
    Last Post: Sep 28, 2011, 4:50 AM
  2. Pass and get parameters from Window
    By AlexMaslakov in forum 1.x Help
    Replies: 1
    Last Post: Aug 19, 2011, 9:16 PM
  3. Replies: 4
    Last Post: May 31, 2011, 12:54 PM
  4. Replies: 1
    Last Post: Nov 29, 2010, 5:15 PM
  5. [CLOSED] Button AJAX Event and Handler Parameters
    By amitpareek in forum 1.x Help
    Replies: 3
    Last Post: Sep 17, 2008, 7:48 PM

Posting Permissions