Ext JS3.4表格grid每一行添加按钮

摘自:https://www.cnblogs.com/280850911/archive/2012/08/10/2632151.html

var data = [
                       { 'id': 1, 'name': '小王', 'sex': '男' },
                       { 'id': 2, 'name': '小李', 'sex': '男' },
                       { 'id': 3, 'name': '小兰', 'sex': '女' }
             ];

            var store = new Ext.data.JsonStore({
                data: data,
                fields: ['id', 'name', 'sex']
            });

            //创建模板 
            var tplCum = new Ext.XTemplate(
                 '<div><table style="border-bottom-style: groove; border-bottom-width: thin">',
                 '<tr>                                                              ',
                 '<td style="width:35px"></td>                                      ',
                 '    <td style="width:300px">                                      ',
                 '        <table><tr>                                               ',
                 '        <td style="width:100px">姓名:{name}</td>                 ',
                 '        <td style="width:100px">性别:{sex}</td>                  ',
                 '        <td >邮箱:</td>                                          ',
                 '        </tr></table>                                             ',
                 '        </td>                                                     ',
                 '    <td style="width:20px"></td>                                 ',
                 '</tr>                                                             ',
                 '<tr style="height:30px;color:blue;vertical-align: middle;">      ',
                 '    <td >意见:</td>                                              ',
                 '    <td ></td>                                                    ',
                 '    <td >提出时间:{Time}</td>                                    ',
                 '</tr>                                                             ', //每行以逗号隔开
                 '</table></div>                                                    '  //最后一行不用逗号
             );
 
             var AdviceGrid = new Ext.grid.GridPanel({
                      store: store,
                      height:300,
                      region: 'center',
                      autoScroll: true,
                      containerScroll: true,
                      stripeRows: true,
                      frame: true,
                      loadMask: {
                          msg: '数据加载中,请稍等......'
                      },
                      cm: new Ext.grid.ColumnModel([new Ext.grid.RowNumberer(),
                             { header: "编号", dataIndex: "Id", tooltip: "编号", sortable: true, hidden: true, width: 50 },
                        //模板
                        { text: '描述', xtype: 'templatecolumn', tpl: tplCum, width: 400 },
                        //按钮
                        { header: "", dataIndex: "c_reply", width: 50,
                          renderer: function (value, cellmeta) { return "<INPUT type='button' value='回复'>";}
                        },
                        { header: "", dataIndex: "c_agree", width: 50,
                          renderer: function (value, cellmeta) { return "<INPUT type='button' value='采纳'>"; }
                         }
           
                         ]),
                      tbar: [{
                          pressed: true,
                          enableToggle: true,
                          text: 'add',
                          id: '_btnShowRead',
                          iconCls: 'add',
                          handler: function () {
           
                          }
                      }, '-', {
                          pressed: true,
                          enableToggle: true,
                          text: 'edit',
                          id: '_btnShowAll',
                          iconCls: 'edit',
                          handler: function () {
           
                          }
                      }],
                      bbar: new Ext.PagingToolbar({
                          pageSize: 20,
                          store: store,
                          displayInfo: true
                      })
              });

                  //添加cell单击事件
             AdviceGrid.addListener('cellclick', cellclick);
             function cellclick(AdviceGrid, rowIndex, columnIndex, e) {
                 if (rowIndex < 0) {
                     return;
                 }
                 var record = AdviceGrid.getStore().getAt(rowIndex); //Get the Record 
                 var id = record.get('id');
                 var fieldName = AdviceGrid.getColumnModel().getDataIndex(columnIndex); //Get field name 
                 if (fieldName == "c_reply") {
                     Ext.Msg.alert('c_reply', rowIndex + "  -  " + id);
                 } else if (fieldName == "c_agree") {
                     Ext.Msg.alert('c_agree', rowIndex + "  -  " + id);
                 }
             }

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值