ggt87125 2009-04-22 21:51
浏览 161
已采纳

关于动态生成tool bar ?

[code="java"] this.gridPanel = new Ext.grid.GridPanel( {
id : 'gridpanel',
store : this.store,
cm : this.cm,
sm : this.sm,
// trackMouseOver: false,
loadMask : true,
// 超过长度带自动滚动条
autoScroll : true,
border : false,
// collapsible: true,
// animCollapse: false,
stripeRows : true,

                    viewConfig : viewConfig,
                    listeners : {
                        'celldblclick' : {// 双击时执行修改
                            fn : this.onEdit,
                            scope : this
                        },
                        'contextmenu' : function(e) {
                            e.stopEvent();
                        }
                    },
                    tbar : this.roleBar,

                    bbar : this.pToolbar
                });

                Ext.Ajax.request( {

                    url : "DATA/control/Permissions.ashx",
                    // disableCaching:false,
                        timout : 300,
                        success : function(response, option) {
                            if (response.responseText == "") {
                                return;
                            } 

/*返回的json : [{"id":"ROLE_ADD","text":"添加","iconCls":"page_add","tooltip":"添加新纪录","handler":"this.createAdd"," scope":"this"} ]
*/
this.roleBar = new Ext.Toolbar(eval('('
+ response.responseText + ')'));
this.roleBar.render('gridpanel');

                        },
                        failure : function() {
                            Ext.Msg.alert("提 示", "权限初始化失败!");
                        },
                        params : {
                            id : "addColumns"
                        }
                    // timeout:5000,
                    });

[/code]

// 生成toolbar 以后 为什么 点击按钮事件的时候错误( 对象不支持此属性或方法 ) , 还有 this.roleBar.render(this.gridPanel.tbar); 的时候 this.gridPanel.tbar 不是对象呢 ?
[b]问题补充:[/b]
[code="java"] var grid = new Ext.grid.GridPanel({ });
tbar.render(grid.tbar); [/code]
[color=red] [b]上面的可以为什么下面的这种就不行呢 ?[/b][/color]
[code="java"] this.grid = new Ext.grid.GridPanel({ });
tbar.render(this.grid.tbar); //错误 this.grid 未定义..[/code]

  • 写回答

2条回答 默认 最新

  • zhoujuan520 2009-04-23 00:11
    关注

    不知道这个是不是你想要的,动态添加工具栏,我帮你做了一个示例
    [code="js"]
    Ext.onReady(function() {
    var myData = [
    ['3m Co',71.72,0.02,0.03,'9/1 12:00am'],
    ['Alcoa Inc',29.01,0.42,1.47,'9/1 12:00am'],
    ['Altria Group Inc',83.81,0.28,0.34,'9/1 12:00am'],
    ['United Technologies Corporation',63.26,0.55,0.88,'9/1 12:00am'],
    ['Verizon Communications',35.57,0.39,1.11,'9/1 12:00am'],
    ['Wal-Mart Stores, Inc.',45.45,0.73,1.63,'9/1 12:00am']
    ];

    var store = new Ext.data.SimpleStore({
        fields: [
           {name: 'company'},
           {name: 'price', type: 'float'},
           {name: 'change', type: 'float'},
           {name: 'pctChange', type: 'float'},
           {name: 'lastChange', type: 'date', dateFormat: 'n/j h:ia'}
        ]
    });
    store.loadData(myData);
    
    var grid = new Ext.grid.GridPanel({
        store: store,
        columns: [
            {id:'company',header: "Company", width: 160, sortable: true, dataIndex: 'company'},
            {header: "Price", width: 75, sortable: true, renderer: 'usMoney', dataIndex: 'price'},
            {header: "Change", width: 75, sortable: true, dataIndex: 'change'},
            {header: "% Change", width: 75, sortable: true, dataIndex: 'pctChange'},
            {header: "Last Updated", width: 85, sortable: true, renderer: Ext.util.Format.dateRenderer('m/d/Y'), dataIndex: 'lastChange'}
        ],
        stripeRows: true,
        autoExpandColumn: 'company',
        height:280,
        width:500,
        tbar : new Ext.Toolbar([{text : '我是第一个tbar上的按钮'}]),
        buttons : [{
            text : '生成tbar',
            handler : function(){
                var tbar = new Ext.Toolbar([{"id":"ROLE_ADD","text":"添加","iconCls":"page_add","tooltip":"添加新纪录","handler":"this.createAdd"," scope":"this"}]);
                tbar.render(grid.tbar);
            }
        }],
        title:'Array Grid'
    });
    grid.render(document.body);
    

    });

    [/code]

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 数学的三元一次方程求解
  • ¥20 iqoo11 如何下载安装工程模式
  • ¥15 本题的答案是不是有问题
  • ¥15 关于#r语言#的问题:(svydesign)为什么在一个大的数据集中抽取了一个小数据集
  • ¥15 C++使用Gunplot
  • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 蓝桥杯单片机第十三届第一场,整点继电器吸合,5s后断开出现了问题