PDA

View Full Version : Is this possible to change Combox store from Xml Reader to Array Store?



sam.arulprakash
21 Jun 2010, 2:49 AM
Hi All,
Is this possible to change Combox store from Xml Reader to Array Store.

First time i have loaded my comboBox with XmlReader and HttpProxy.



Load:function(Url,Param)
{
if(Url!=null)
<%= this.ID%>_ds.proxy.conn.url = Url;
if(Param==null)
<%= this.ID%>_ds.load();
else
<%= this.ID%>_ds.load(Param);
}

But in the same combobox i am in need to populate value from array store....


LoadJavaScript:function (objArray)
{

var a=JSON.stringify(objArray);//Javascript Object to json.
<%= this.ID%>_ArrayStore.loadData(a);
<%= this.ID%>.bindStore(<%= this.ID%>_ArrayStore,true);
}

The previous code doesn't throw any error.But not working?.....

so i how to change combobox store from XML to Arraystore?...

Help Me.

Thanks in advance.

Condor
21 Jun 2010, 2:53 AM
loadData expects an object and not a string!

sam.arulprakash
21 Jun 2010, 3:02 AM
Thanks Condor for your reply.

Now i have changed my parameter and give Array(Arr) Object as a parameter.

Now also its is not bind to the combo.



var javaObj=function()
{
var SHPIMO_NR,SHPNAME;
}

var testObj;
var Arr=new Array();
testObj=new javaObj();
testObj.SHPIMO_NR='Test';
testObj.SHPNAME='Test1';
Arr[0]=testObj;
testObj=new javaObj();
testObj.SHPIMO_NR='Test2';
testObj.SHPNAME='Test12';
Arr[1]=testObj;
testObj=new javaObj();
testObj.SHPIMO_NR='Test3';
testObj.SHPNAME='Test13';
Arr[2]=testObj;

Condor
21 Jun 2010, 3:41 AM
Really weird way to define javascript objects...

Also, this will create data for a JsonReader and not for an ArrayReader!

sam.arulprakash
21 Jun 2010, 8:52 PM
Thanks Condor.

Now it is working Fine.... :)


<%= this.ID%>_ArrayStore=new Ext.data.ArrayStore
({
//fields: ['<%=ValueField %>', '<%=DisplayField %>'],
fields: [{name:'<%=ValueField %>'},{name:'<%=DisplayField %>'}]
//data : [['Tess','Tess1'],['Tess1','Tess2'],['Tess2','Tess3']]
});
var <%= this.ID%>_Arr=[['Tess','Tess1'],['Tess1','Tess2'],['Tess2','Tess3']];

sam.arulprakash
21 Jun 2010, 11:03 PM
Hi all,

when i have try to switch (ComboBox store) between Array Store to Xml Reader i am getting this error.

Ext.data.DataProxy: DataProxy attempted to execute an API-action but found an undefined url / function. Please review your Proxy url/api-configuration.

But the reverse (Xml Reader => Array Store => Xml Reader) working fine.

Any suggestion....

Thanks in advance.

Regards,
Arul Prakash.M

Condor
21 Jun 2010, 11:54 PM
Your arraystore contains local data, so you need to configure your combobox with mode:'local'.

sam.arulprakash
22 Jun 2010, 4:23 AM
Thanks Condor for your suggestion.
That issue was fixed.

Initially i have not configured store--in ComboBox.
ComboBox store dynamically assaigned by using BindStore.Because,
at the time of button click only i am in need to bind the combobox.
This is working fine for me.

But,
After the page Load,When we click the ComboBox, Javascript Error Thrown by IE is(this.store is null not an object).
I hope source of this error is 'store is assigned at the time Clicking'.

Any suggestions to avoid this javascript error.

Thanks in advance.


This is my sample HTML Code.

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<link rel="stylesheet" type="text/css" href="lib/ext300/resources/css/ext-all.css" />
<script language="javascript" src="lib/ext300/adapter/ext/ext-base.js"></script>
<script language="javascript" src="lib/ext300/ext-all.js"></script>
<link rel="stylesheet" type="text/css" href="lib/css/style.css" />
<link rel="stylesheet" type="text/css" href="lib/css/c.css" />
<script language="javascript">
function BindArrayStore()
{
var Arr1=[['Tess','Tess1'],['Tess1','Tess2'],['Tess2','Tess3']];
TestCombo.LoadJavaScriptArray(Arr1);
}
function BindProxyStore()
{
TestCombo.Load(null,null);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<input type="text" runat="server" id="ComboTest" />
<input type="button" runat="server" id="SetArrayStore" onclick="BindArrayStore();" value="SetArrayStore" runat="server"/>
<input type="button" runat="server" id="Text2" value="SetProxyStore" onclick="BindProxyStore();" runat="server"/>

<div>
<script language="javascript" type="text/javascript">
var TestCombo;
var TestCombo_ds;
var TestCombo_ArrayStore;

Ext.onReady(function()
{
Ext.QuickTips.init();

TestCombo_ds = new Ext.data.Store
({
proxy: new Ext.data.HttpProxy
({
url: 'Test.asmx/GetShips',
method: "POST",
disableCaching: true
}),
reader: new Ext.data.XmlReader
({
record: 'Rows',
id: 'SHPFLAG',
totalRecords: 'totalRecords'
},
['SHPFLAG','SHPNAME']),
autoLoad:false,
listeners:
{
load:function()
{
},
exception: function(proxy, type, action, options, response, e)
{
alert('type: ' + type + '\naction: ' + action + '\nerror: ' + e + '\nresponse: ' + response.responseText);
},
loadexception:function(obj)
{
}
}
});

TestCombo_ArrayStore=new Ext.data.ArrayStore
({
fields: [{name:'SHPNAME'},{name:'SHPFLAG'}]
});

TestCombo = new Ext.form.ComboBox({
mode:'local',
displayField: 'SHPNAME',
applyTo: 'ComboTest',
valueField: 'SHPFLAG',
hiddenName: 'SHPFLAG',

//Param => Json String like '{params: {pid: value}'
Load:function(Url,Param)
{
if(Url!=null)
TestCombo_ds.proxy.conn.url = Url;
if(Param==null)
TestCombo_ds.load();
else
TestCombo_ds.load({params:Param});

TestCombo.bindStore(TestCombo_ds);
},
LoadJavaScriptArray:function (objArray)
{
TestCombo_ArrayStore.loadData(objArray);
TestCombo.bindStore(TestCombo_ArrayStore,false);
}
});

//var Arr2=[['Tess','Tess1'],['Tess1','Tess2'],['Tess2','Tess3']];
//TestCombo.LoadJavaScriptArray(Arr2);
//TestCombo.LoadJavaScriptArray();

});

</script>
</div>
</form>
</body>
</html>

sam.arulprakash
22 Jun 2010, 4:29 AM
Thanks Condor for your suggestion.
That issue was fixed.
Initially i have not configured store--in ComboBox.
ComboBox store dynamically assaigned by using BindStore.Because,
at the time of button click only i am in need to bind the combobox.
This is working fine for me.
But,
After the page Load,When we click the ComboBox, Javascript Error Thrown by IE is(this.store is null not an object).
I hope source of this error is 'store is assigned at the time Clicking'.
Any suggestions to avoid this javascript error.
Thanks in advance.

This is my sample HTML Code.

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<link rel="stylesheet" type="text/css" href="lib/ext300/resources/css/ext-all.css" />
<script language="javascript" src="lib/ext300/adapter/ext/ext-base.js"></script>
<script language="javascript" src="lib/ext300/ext-all.js"></script>
<link rel="stylesheet" type="text/css" href="lib/css/style.css" />
<link rel="stylesheet" type="text/css" href="lib/css/c.css" />
<script language="javascript">
function BindArrayStore()
{
var Arr1=[['Tess','Tess1'],['Tess1','Tess2'],['Tess2','Tess3']];
TestCombo.LoadJavaScriptArray(Arr1);
}
function BindProxyStore()
{
TestCombo.Load(null,null);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<input type="text" runat="server" id="ComboTest" />
<input type="button" runat="server" id="SetArrayStore" onclick="BindArrayStore();" value="SetArrayStore" runat="server"/>
<input type="button" runat="server" id="Text2" value="SetProxyStore" onclick="BindProxyStore();" runat="server"/>

<div>
<script language="javascript" type="text/javascript">
var TestCombo;
var TestCombo_ds;
var TestCombo_ArrayStore;
Ext.onReady(function()
{
Ext.QuickTips.init();

TestCombo_ds = new Ext.data.Store
({
proxy: new Ext.data.HttpProxy
({
url: 'Test.asmx/GetShips',
method: "POST",
disableCaching: true
}),
reader: new Ext.data.XmlReader
({
record: 'Rows',
id: 'SHPFLAG',
totalRecords: 'totalRecords'
},
['SHPFLAG','SHPNAME']),
autoLoad:false,
listeners:
{
load:function()
{
},
exception: function(proxy, type, action, options, response, e)
{
alert('type: ' + type + '\naction: ' + action + '\nerror: ' + e + '\nresponse: ' + response.responseText);
},
loadexception:function(obj)
{
}
}
});
TestCombo_ArrayStore=new Ext.data.ArrayStore
({
fields: [{name:'SHPNAME'},{name:'SHPFLAG'}]
});

TestCombo = new Ext.form.ComboBox({
mode:'local',
displayField: 'SHPNAME',
applyTo: 'ComboTest',
valueField: 'SHPFLAG',
hiddenName: 'SHPFLAG',

//Param => Json String like '{params: {pid: value}'
Load:function(Url,Param)
{
if(Url!=null)
TestCombo_ds.proxy.conn.url = Url;
if(Param==null)
TestCombo_ds.load();
else
TestCombo_ds.load({params:Param});
TestCombo.bindStore(TestCombo_ds);
},
LoadJavaScriptArray:function (objArray)
{
TestCombo_ArrayStore.loadData(objArray);
TestCombo.bindStore(TestCombo_ArrayStore,false);
}
});

//var Arr2=[['Tess','Tess1'],['Tess1','Tess2'],['Tess2','Tess3']];
//TestCombo.LoadJavaScriptArray(Arr2);
//TestCombo.LoadJavaScriptArray();

});

</script>
</div>
</form>
</body>
</html>

Condor
22 Jun 2010, 4:50 AM
You can't create a combobox without a store, even when it's just an empty store, e.g.

store: []

sam.arulprakash
22 Jun 2010, 4:58 AM
Thanks condor.
Your is answer is simple but its fix the problem.

Thanks & Regards,
Arul Prakash.M