PDA

View Full Version : how to access data in toolbars?



arnigudj
13 Jul 2007, 4:00 AM
I'm using a submenu in a toolbar that uses the Datepicker. When someone picks a date I want the date handler to access the text from the submenu. I'm new to Extjs and I've tried item.text and so on, but haven't been able to get it right.

Here is an example code:


var sort = new Ext.menu.DateMenu({
handler : function(dp, date){
//How can I access the text here? (see below)

}
});

var menu = new Ext.menu.Menu({
id: 'mainMenu',
items: [ {
text: 'pick a date',
cls: 'calendar',
menu: sort// <-- submenu by reference
}]});

var gridHeaderPanel = grid.getView().getHeaderPanel(true);
var tb = new Ext.Toolbar(
gridHeaderPanel,
[{
cls: 'x-btn-text-icon bmenu', // icon and text class
text: 'THE TEXT I WANT TO GET',
menu: sort // assign menu by instance
}]});
any ideas?

ps. The Extjs is awesome!

arnigudj
13 Jul 2007, 4:18 AM
The code was a bit wrong.. this is the correct code:

var sort = new Ext.menu.DateMenu({
handler : function(dp, date){
//How can I access the text here? (see below)

}
});

var menu = new Ext.menu.Menu({
id: 'mainMenu',
items: [ {
text: 'pick a date',
cls: 'calendar',
menu: sort// <-- submenu by reference
}]});

var gridHeaderPanel = grid.getView().getHeaderPanel(true);
var tb = new Ext.Toolbar(
gridHeaderPanel,
[{
cls: 'x-btn-text-icon bmenu', // icon and text class
text: 'THE TEXT I WANT TO GET',
menu: menu // assign menu by instance
}]});

para
13 Jul 2007, 5:16 AM
User firebug to set a breakpoint within the handler function. From there, you can use the 'script' tab on firebug to try things (the 'watch' variables). The resulting code should be something close to


tb.items.items[0].text;

With firebug you can do anything! :)

arnigudj
13 Jul 2007, 5:50 AM
Iwould like to be able to send it to the DateMenu function like so:


handler: function(dp, date, item){alert(item.id);}

some thing like parent.item or menu.item... just not shure what to write.

can't really use "tb.items.items[0].text;" cause the number of items vary by what my json request returns.

para
13 Jul 2007, 6:02 AM
I understand.
The best solution is still to use Firebug. Set a breakpoint within the handler and then do the action that calls the handler. It should stop and allow you to add Watch variables. Look around at that point and see what 'this' is, see what arguments are passed to the handler, etc. You may end up having to add something to the scope in the handler function call.
Sorry I can't help with code... got issues of my own :)