PDA

View Full Version : [CLOSED] [2.2+] Combobox load single record to the store before trigger



ViDom
May 29, 2013, 2:59 PM
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

Daniil
May 29, 2013, 4:06 PM
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

ViDom
May 31, 2013, 9:40 AM
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?

Daniil
May 31, 2013, 11:53 AM
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 */);

ViDom
May 31, 2013, 4:23 PM
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?

Daniil
Jun 03, 2013, 3:52 AM
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"
}
});


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;

ViDom
Jun 03, 2013, 6:29 AM
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 (http://forums.ext.net/showthread.php?22653-CLOSED-How-to-set-default-value-on-remote-combobox&p=105666&viewfull=1#post105666) 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?

Daniil
Jun 03, 2013, 11:54 AM
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.




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.



Please advice this (http://forums.ext.net/showthread.php?22653-CLOSED-How-to-set-default-value-on-remote-combobox&p=105666&viewfull=1#post105666) 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?

ViDom
Jun 04, 2013, 7:27 AM
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.

Daniil
Jun 04, 2013, 11:05 AM
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" } };

ViDom
Jun 06, 2013, 8:32 AM
Sorry, I didn't understand why you can use this approach. Please elaborate.

Well there is a problem with mechanism of closing sessions. We created it to open new nhibernate session on begin of request and close it on end request. (beetwen opened and closed session is the same for all objects we use). when I load combobox with a query there is a multithread and session is closing in time when for e.g. last loading is in progress. Rebuilding this mechanism is not an option in my case.



combo.GetStore().Data = new object[]{Id=1,Name="name"};


This not working with my custom Combobox with sample it's working just fine. I'm sure of that Data is loaded only once at OnPrerender event.
Have any other ideas what can cause this?

Daniil
Jun 06, 2013, 1:14 PM
This not working with my custom Combobox with sample it's working just fine. I'm sure of that Data is loaded only once at OnPrerender event.
Have any other ideas what can cause this?

It is hard to say something without a test case.