[CLOSED] [2.2+] Combobox load single record to the store before trigger

Page 1 of 2 12 LastLast
  1. #1

    [CLOSED] [2.2+] Combobox load single record to the store before trigger

    Hi,

    I've this code from version v1.5:
    int id = 12;
    string name = "some name to display";
    combobox.Store.Add(new { Id = id, Name = name });
    combobox.Value = id;
    combobox.Text = name;
    How can I handle this in v2.2+ today svn update?

    Thanks,
    ViDom
    Last edited by Daniil; Jun 11, 2013 at 4:25 AM. Reason: [CLOSED]
  2. #2
    Hi @ViDom,

    Essentially, it was a hack in v1. A kind of unsupported behavior.

    This problem is discussed here in the context of v2.
    http://forums.ext.net/showthread.php?22653
  3. #3
    Quote Originally Posted by Daniil View Post
    Hi @ViDom,

    Essentially, it was a hack in v1. A kind of unsupported behavior.

    This problem is discussed here in the context of v2.
    http://forums.ext.net/showthread.php?22653
    I can search on my remote combobox. So maybe is there a way to send query to the handler with an id of needed item?
  4. #4
    Quote Originally Posted by ViDom View Post
    I can search on my remote combobox. So maybe is there a way to send query to the handler with an id of needed item?
    Are going to do it on initial page load? Do you understand correctly?

    Generally, you can do it via:
    comboBox.getStore().load(/* params */);
  5. #5
    Quote Originally Posted by Daniil View Post
    Are going to do it on initial page load? Do you understand correctly?

    Generally, you can do it via:
    comboBox.getStore().load(/* params */);
    and params are string or something else like array of Ext.Net.Parameter?

    If I'll do this I think there will be another problem with load list only ones. For now combo store load ones on trigger click downarrow of combobox is there a way to delete query after use of your code?
    Last edited by ViDom; May 31, 2013 at 4:27 PM.
  6. #6
    Quote Originally Posted by ViDom View Post
    and params are string or something else like array of Ext.Net.Parameter?
    It should be a JavaScript object.
    comboBox.getStore().load({
        params: {
            testParamName: "testParamValue"
        }
    });
    Quote Originally Posted by ViDom View Post
    If I'll do this I think there will be another problem with load list only ones. For now combo store load ones on trigger click downarrow of combobox is there a way to delete query after use of your code?
    I think this should help.
    delete comboBox.lastQuery;
  7. #7
    Quote Originally Posted by Daniil View Post
    It should be a JavaScript object.
    comboBox.getStore().load({
        params: {
            testParamName: "testParamValue"
        }
    });


    I think this should help.
    delete comboBox.lastQuery;
    Ok but I've a more complex scenario. I've building all ext.net controls dynamically(all posible scenarios: create new element, edit existing one(here is a problem with load remote combobox),delete existing element) If I'll do some javascript method in load each time request came then If user choose some other than loaded before value. doesn't your solution restart this new value to old one? How should I check if user choose some other than value choosed in create new element?(I'm not sure I'm clear enough here so please confirm if you understand:) )

    And how can I get this params on handler ? - I found out it on handler side param can be extracted like this:
    context.Request.Form["nameOfParam"]
    But unfortunatly I can't use this js approach because of issue of nhibernate session handling in my app.

    Please advice this work randomly
    (example: if I've more than 1 combobox with remote loading then:
    1. all comboboxes have Selected items collection with 1 correct item per combobox
    2. In random combobox this item is displayed correctly only when I've breakpoint in app(if i reload page this start changing combo which display correctly before reload got blank and another one which was blank start display correctly)
    3.without breakpoint combobox aways display empty(without event empty text)

    Do you need (not simple to make) example for examination?
    Last edited by ViDom; Jun 03, 2013 at 11:00 AM.
  8. #8
    Quote Originally Posted by ViDom View Post
    Ok but I've a more complex scenario. I've building all ext.net controls dynamically(all posible scenarios: create new element, edit existing one(here is a problem with load remote combobox),delete existing element) If I'll do some javascript method in load each time request came then If user choose some other than loaded before value. doesn't your solution restart this new value to old one?
    Do you mean a "store.load()" call under "your solution"? If yes, then it is executed once in the place where you put it. It is not like an event listener.


    Quote Originally Posted by ViDom View Post
    And how can I get this params on handler ? - I found out it on handler side param can be extracted like this:
    context.Request.Form["nameOfParam"]
    But unfortunatly I can't use this js approach because of issue of nhibernate session handling in my app.
    Sorry, I didn't understand why you can use this approach. Please elaborate.

    Quote Originally Posted by ViDom View Post
    Please advice this work randomly
    (example: if I've more than 1 combobox with remote loading then:
    1. all comboboxes have Selected items collection with 1 correct item per combobox
    2. In random combobox this item is displayed correctly only when I've breakpoint in app(if i reload page this start changing combo which display correctly before reload got blank and another one which was blank start display correctly)
    3.without breakpoint combobox aways display empty(without event empty text)

    Do you need (not simple to make) example for examination?
    Well, hard to say anything concrete without a test case. I guess the breakpoint allows the Store to finish its load request. The ComboBox sets its value.

    So, where do you put a breakpoint? And how do you apply a value to ComboBox?
  9. #9
    Quote Originally Posted by Daniil View Post
    Do you mean a "store.load()" call under "your solution"? If yes, then it is executed once in the place where you put it. It is not like an event listener.




    Sorry, I didn't understand why you can use this approach. Please elaborate.



    Well, hard to say anything concrete without a test case. I guess the breakpoint allows the Store to finish its load request. The ComboBox sets its value.

    So, where do you put a breakpoint? And how do you apply a value to ComboBox?
    here is sample for recreate:
    handler.ashx
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using Ext.Net;
    
    namespace Ext.NetTest2.x
    {
        /// <summary>
        /// Summary description for HandlerProxy
        /// </summary>
        [Serializable]
        public class MyClass
        {
            public int Id { get; set; }
            public string Name { get; set; }
            public MyClass(int id, string name)
            {
                Id = id;
                Name = name;
            }
        }
        public class HandlerProxy : IHttpHandler
        {
            private List<MyClass> myClasses = new List<MyClass>()
                                              {
                                                  new MyClass(1,"first"),
                                                  new MyClass(2,"second"),
                                                  new MyClass(3,"third")
                                              };
            public void ProcessRequest(HttpContext context)
            {
    
                string sessionName = string.Empty;
                string query = string.Empty;
                if (!string.IsNullOrEmpty(context.Request["session_name"]))
                    sessionName = context.Request["session_name"];
                if (!string.IsNullOrEmpty(context.Request["query"]))
                    query = context.Request["query"];
                if (!string.IsNullOrEmpty(query))
                {
                    List<MyClass> queryResult = myClasses.Where(x => x.Name.ToLower().Contains(query.ToLower())).ToList();
                    context.Response.Write(JSON.Serialize(queryResult));
                }
                else
                {
                    context.Response.Write(JSON.Serialize(myClasses));
                }
    
            }
    
            public bool IsReusable
            {
                get
                {
                    return false;
                }
            }
        }
    }
    aspx
    <%@ Page Language="C#" %>
    <%@ Register tagPrefix="ext" assembly="Ext.Net" namespace="Ext.Net" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <script runat="server">
    
        public class ComboboxLoadOnExpand : Ext.Net.ComboBox
        {
            private Ext.Net.Store store;
    
            protected override void OnInit(EventArgs e)
            {
                base.OnInit(e);
                store = new Ext.Net.Store();
                Ext.Net.JsonReader reader = new JsonReader();
                Ext.Net.Model model = new Ext.Net.Model {ID = this.ID + "_model"};
                model.Fields.AddRange(new List<ModelField> {new ModelField("Id", ModelFieldType.Int), new ModelField("Name", ModelFieldType.String)});
                reader.IDProperty = "Id";
                reader.MessageProperty = "Name";
                reader.Root = "data";
                reader.TotalProperty = "total";
                Ext.Net.AjaxProxy proxy = new Ext.Net.AjaxProxy();
                proxy.Url = "~/HandlerProxy.ashx";
                proxy.ActionMethods.Read = HttpMethod.POST;
                proxy.Timeout = 30000;
                proxy.Reader.Add(reader);
                store.ID = this.ID + "_Store";
                store.AutoLoad = false;
                store.WarningOnDirty = false;
                store.Model.Add(model);
                store.Proxy.Add(proxy);
                this.Store.Add(store);
                store.Parameters.Add(new StoreParameter("session_name", "session"));
                //store.BaseParams["session_name_param1"] = JSON.Serialize(new List<Parameter>{new Parameter(0,"param1"),new Parameter(2,"param2")});
                this.DisplayField = "Name";
                this.ValueField = "Id";
                this.Editable = true;
                this.TypeAhead = false;
                this.MinChars = 1;
                this.TriggerAction = TriggerAction.All;
            }
        }
    
        private ComboboxLoadOnExpand combo;
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            combo = new ComboboxLoadOnExpand{ID="combo",Height=26};
            comboContainer.Items.Add(combo);
        }
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            if (!X.IsAjaxRequest)
            {
                combo.GetStore().DataSource = new object[] {new {Id = 2, Name = "second"}};
            }
        }
    
    </script>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <ext:ResourceManager runat="server"></ext:ResourceManager>
        <ext:Viewport runat="server" ID="viewport">
            <LayoutConfig>
                <ext:VBoxLayoutConfig runat="server" Align="Stretch"/>
            </LayoutConfig>
            <Items>
                <ext:Toolbar runat="server" ID="toolbar" Height="40">
                    <LayoutConfig>
                        <ext:HBoxLayoutConfig runat="server" Align="Stretch"/>
                    </LayoutConfig>
                    <Items>
                        <ext:Button runat="server" ID="btnSample" Text="This is only for simulate layout"></ext:Button>
                    </Items>
                </ext:Toolbar>
                <ext:Container runat="server" ID="container" Flex="1" Layout="FitLayout">
                    <Items>
                        <ext:Container runat="server" ID="comboContainer">
                        </ext:Container>
                    </Items>
                </ext:Container>
            </Items>
        </ext:Viewport>
    </body>
    </html>
    web.config httpHandlers section
    <httpHandlers>
          <add verb="*" path="~/HandlerProxy.ashx" validate="false" type="Ext.NetTest2.x.HandlerProxy, Ext.NetTest2.x" />
          <add path="*/ext.axd" verb="*" type="Ext.Net.ResourceHandler" validate="false" />
    </httpHandlers>
    It's reproduce problem with remote loading default value. It's important to use handler here.

    addding ListItem with Index = 0 to SelectedItems collection doesn't change anything as well.
    Last edited by ViDom; Jun 04, 2013 at 7:56 AM.
  10. #10
    Thank you for the example.

    Please replace
    combo.GetStore().DataSource = new object[] { new { Id = 2, Name = "second" } };
    with
    combo.GetStore().Data = new object[] { new { Id = 2, Name = "second" } };
Page 1 of 2 12 LastLast

Similar Threads

  1. [CLOSED] Load combobox's store
    By romeu in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Jan 11, 2013, 1:50 PM
  2. Replies: 7
    Last Post: Dec 18, 2012, 6:58 PM
  3. Replies: 2
    Last Post: Nov 17, 2012, 3:20 AM
  4. Problem with load record into ComboBox
    By JosefTrbusek in forum 2.x Help
    Replies: 3
    Last Post: Sep 09, 2012, 7:02 AM
  5. How to load pages in same tab with single iframe
    By NishaLijo in forum 1.x Help
    Replies: 0
    Last Post: Aug 19, 2010, 10:39 AM

Tags for this Thread

Posting Permissions