PDA

View Full Version : Dynamically populated toolbar menu



luka.suzberic
6 Sep 2010, 6:52 AM
Hi,
i was wondering is it possibile to dynamicaly populate toolbar menu?
e.g. load it from DB like combobox

thanx

Condor
6 Sep 2010, 6:55 AM
Do an Ajax request to the server and have your server return a JSON array with all button configs.

In the success handler, add these buttons to the toolbar and call doLayout.

ps. You can also use the LiteRemoteComponent plugin for this.

luka.suzberic
14 Sep 2010, 10:52 AM
Hi, again
i need help, could anyone please submit excample how to load menu from this json object(store)
{rows:",{text:'Tele2', handler:'onItemClick'},{text:'Others', handler:'onItemClick'},{text:'FMCG', handler:'onItemClick'},{text:'Active Sales', handler:'onItemClick'},{text:'Web', handler:'onItemClick'},{text:'B2B', handler:'onItemClick'},{text:'Unallocated', handler:'onItemClick'}"}

Condor
15 Sep 2010, 12:09 AM
Couldn't you create valid JSON instead of putting everything in a string?

luka.suzberic
15 Sep 2010, 2:16 AM
lets asume that i have valid JSON(this one i copied after few variances of output it didnt work even when it was in form {rows:[{"text":"Tele2","handler":"onItemClick"},{"text":"Others","handler":"onItemClick"},{"text":"FMCG","handler":"onItemClick"},{"text":"Active Sales","handler":"onItemClick"},{"text":"Web","handler":"onItemClick"},{"text":"B2B","handler":"onItemClick"},{"text":"Unallocated","handler":"onItemClick"}]} but it didn't work.
i'm trying to get it trough a loop :)

Condor
15 Sep 2010, 3:36 AM
Your handlers are strings, but they should be functions.

(functions are not part of the JSON standard, so you need to use an extension on your JSON encoder on the server)

luka.suzberic
15 Sep 2010, 4:08 AM
lol to my self, this is my handler
function onItemClick(item){ level1.setParam(item.text); level1.load();
}
so i don't even need to send diferent handlers from the server because php script decides which csmt to call acording to params sent trougs request

luka.suzberic
15 Sep 2010, 6:13 AM
SOLVED!!!!!!!!!!!

var something= new Ext.menu.Menu({
id:'something'
});
var menuDef = new Ext.data.Store({
reader: new Ext.data.JsonReader({
fields: ['text'],
root: 'rows'
}),
proxy: new Ext.data.HttpProxy({
url: 'php/getMenu.php'
}),
//autoLoad:true,
listeners:{
load:function(){
var i=0;
var k=menuDef.getCount();
var t;
for(i=0;i<k;i++) {
t=new Ext.menu.Item({
text:menuDef.getAt(i).get('text')
,handler:onItemClick
});
Ext.getCmp('something').add(t);
}
}
}

});
menuDef.load();
function onItemClick(item){
someStore.setParam(item.text), someStore.load();
}
var tool_bar =
new Ext.Toolbar({
items: [{
xtype:'tbbutton',
text:'Something else'
,menu: something
}]
});