Results 1 to 8 of 8

Thread: Dynamically populated toolbar menu

  1. #1

    Default Dynamically populated toolbar menu

    Hi,
    i was wondering is it possibile to dynamicaly populate toolbar menu?
    e.g. load it from DB like combobox

    thanx

  2. #2
    Sencha User Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,245

    Default

    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.

  3. #3

    Default

    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'}"}

  4. #4
    Sencha User Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,245

    Default

    Couldn't you create valid JSON instead of putting everything in a string?

  5. #5

    Default

    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

  6. #6
    Sencha User Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,245

    Default

    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)

  7. #7

    Default

    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

  8. #8

    Default

    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
    }]
    });

Similar Threads

  1. Dynamically adding toolbar item to top toolbar of a panel
    By rahesh in forum Ext 2.x: Help & Discussion
    Replies: 4
    Last Post: 30 Aug 2010, 4:12 AM
  2. Ajax populated Comboboxes in a Ajax populated form
    By netsuo in forum Ext 3.x: Help & Discussion
    Replies: 2
    Last Post: 17 Jun 2010, 12:41 AM
  3. Replies: 6
    Last Post: 23 Mar 2010, 4:09 PM
  4. Reset Dynamically populated store.
    By nayak14 in forum Ext 3.x: Help & Discussion
    Replies: 0
    Last Post: 19 Oct 2009, 9:41 PM
  5. [SOLVED] Dynamically add Action/Menu to Toolbar SplitButton
    By fendrikat in forum Ext 2.x: Help & Discussion
    Replies: 1
    Last Post: 29 Jan 2008, 10:48 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •