PDA

View Full Version : Onchange to reload store?



mtrax
13 Sep 2009, 2:53 AM
is it possible to trigger a load of a Data Store from an Onchange event outside the Ext?
ie on a normal select box?
or does it need to be within a Ext Panel etc.. ?

eg <select name="host" id="host" onChange="test1()" >

function test1 {
var sel = document.getElementById("sdate");
var sdate = sel.options[sel.selectedIndex].value;

var sel = document.getElementById("host");
var host = sel.options[sel.selectedIndex].value;

ipstore.baseParams = { host: host, sdate: sdate };

ipstore.load();
}

saJoshua
13 Sep 2009, 9:39 AM
native HTML elements have certain events that are published. Some of those available on the SELECT element are onfocus, onblur, onchange, etc. SEE http://www.w3schools.com/TAGS/tag_Select.asp

If you can access your store, or the component that it's bound to, you can reload the store. Use


yourStore.reload();
or
yourComponent.store.reload();

mtrax
13 Sep 2009, 1:25 PM
native HTML elements have certain events that are published. Some of those available on the SELECT element are onfocus, onblur, onchange, etc. SEE http://www.w3schools.com/TAGS/tag_Select.asp

If you can access your store, or the component that it's bound to, you can reload the store. Use


yourStore.reload();
or
yourComponent.store.reload();


I get a "yourstore.reload" not defined or unknown , so what is this "YourComponent"?

note my Panel is current build from a OnReady event
eg
"Ext.onReady(function(){....."
..
var ipstore = new Ext.data.Store({
// store configs
autoDestroy: true,
autoLoad: true,
proxy: new Ext.data.HttpProxy({
url: 'list_array.php', // File to connect to
method: 'GET',
}),
baseParams:{
sdate: sdate,
host: host
},
// reader configs
reader:ip_reader
});

mtrax
13 Sep 2009, 6:05 PM
I'm guessing this is a "scope" issue.

how do I call my function in the correct scope

note I'm using the following code to fire the function (reloadchart)


var hostid = Ext.get('host');
hostid.on('change', reloadchart())



function reloadchart()
{
alert('reloading...')
var sel = document.getElementById("sdate");
var sdate = sel.options[sel.selectedIndex].value;

var sel = document.getElementById("host");
var host = sel.options[sel.selectedIndex].value;

ipstore.baseParams = { host: host, sdate: sdate };

ipstore.load();
}

mtrax
13 Sep 2009, 6:05 PM
I'm guessing this is a "scope" issue.

how do I call my function in the correct scope

note I'm using the following code to fire the function (reloadchart)

var hostid = Ext.get('host');
hostid.on('change', reloadchart())


function reloadchart()
{
alert('reloading...')
var sel = document.getElementById("sdate");
var sdate = sel.options[sel.selectedIndex].value;

var sel = document.getElementById("host");
var host = sel.options[sel.selectedIndex].value;

ipstore.baseParams = { host: host, sdate: sdate };

ipstore.load();
}