PDA

View Full Version : Change datastore of grid by click



falz
8 Oct 2007, 7:07 AM
Hi, i don't know how to change the datastore of a grid by a click. I have a list (a combobox) with many possibilities of content for my data grid, and when the user choose a content, it must change the content in the grid.. i have found examples but there are not the same thing, or i don't have understood (which is possible also...)

here my code :



var store = new Ext.data.JsonStore({
url: 'listingClientsJson.php',
root: 'libel',
fields: ['id','libel']
});

var combo = new Ext.form.ComboBox({
store: storeClients,
displayField:'libel',
typeAhead: true,
triggerAction: 'all',
emptyText:'Choisir un compte client...',
loadingText:'Chargement...',
selectOnFocus:true,
width:135
});

combo.addListener('select', function(){ alert(this.value) ;
// should be something as "changeContent(this.value) ;
}



any help should be very appreciated.. thanks

Footeuz
8 Oct 2007, 7:56 AM
you have to put


combo.on('select', function() {
ds_grid.load(
{params:{
combo_filtre: combo.getValue()
}}
);
}


where ds_grid is your grid's data store

falz
10 Oct 2007, 6:55 AM
thanks, but i don't see what your combo_filtre should do? in fact, i want to do the same thing that in this example (the first) : http://www.openntf.org/extnd/demo.nsf/demo-singlecategory-views.html!OpenPage

falz
11 Oct 2007, 12:05 AM
Nobody?

fay
11 Oct 2007, 12:16 AM
What Footeuz is demonstrating to you is that when an item is selected in your combo, you reload the data for store using the selected item's value to filter it - the assumption is that listingClientsJson.php will filter your back-end data depending on this value. It's like calling the store's url with:


listingClientsJson.php?combo_filtre=/* value */

With this method, it's up to you to write the PHP to filter the data.

You could also use filter (http://extjs.com/deploy/ext/docs/output/Ext.data.Store.html#filter) or query (http://extjs.com/deploy/ext/docs/output/Ext.data.Store.html#query) to limit what's displayed in the grid.

falz
12 Oct 2007, 12:58 PM
yes of course!! it's simple in fact.... yes... thank you very much!