EasyUI Forum
October 31, 2025, 03:59:34 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: How add MenuButton to toolbar from js  (Read 7506 times)
waltex
Newbie
*
Posts: 3


View Profile Email
« on: December 17, 2015, 02:49:54 AM »


i can add a MenuButton  to toolbar for pivogrid  using only javascript statements.


Code:
 toolbar: [{
                    //text: 'Layout',
                    handler: function () {
                        $('#dg2').pivotgrid('layout');
                    }
                }, {iconCls: 'icon-reload',
                    text: 'Elabora',
                    handler: function () {
                        load_dg2();
                    }}, {iconCls: 'icon-excel1',
                    text: 'Esporta',
                    handler: function () {
                        JSONToCSVConvertor2($('#dg2').pivotgrid('getRoots'), 'pivot', 'label');
                    }}, {iconCls: 'icon-database_edit',
                    text: 'parametri pivot',
                    handler: function () {
                        $('#dg2').pivotgrid('layout')
                    }}],

Logged
jarry
Administrator
Hero Member
*****
Posts: 2300


View Profile Email
« Reply #1 on: December 18, 2015, 12:10:39 AM »

Please try to call the 'buildToolbar' function to build the toolbar via javascript code.
Code:
function buildToolbar(conf){
    var tb = $('<div></div>').appendTo('body');
    $.map(conf, function(options){
        var type = options.type || 'linkbutton';
        var a = $('<a href="#"></a>').appendTo(tb);
        a[type]($.extend({}, options, {
            plain:true,
            onClick: options.onClick||options.handler
        }));
    });
    return tb;
}

$(function(){
    var conf = [{
        text:'Add',
        iconCls:'icon-add',
        handler:function(){alert('add')}
    },{
        text:'Cut',
        iconCls:'icon-cut',
        handler:function(){alert('cut')}
    },{
        text:'Save',
        iconCls:'icon-save',
        type:'menubutton',
        menu: '#mm',
        handler:function(){alert('save')}
    }];
    $('#dg').datagrid({
        toolbar: buildToolbar(conf)
    });
})
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!