Extjs4.2 GridPanel中显示单选按钮

效果:如上图。

代码:其中需要显示单选按钮的列

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
{
                    dataIndex: 'FeeModel',
                    text: '收費模式',
                    flex: 1,
                    align: 'left',
                    radioValues: [{ "inputValue": "1", "boxLabel": "高級收費模式" }, { "inputValue": "2", "boxLabel": "简单收费模式" }, { "inputValue": "3", "boxLabel": "不收费模式" }],
                    renderer:function(value, metaData, record, rowIndex, colIndex, store, view) { 
                        var column = view.getGridColumns()[colIndex], 
                            html = ''
                        Ext.each(column.radioValues, function(rec) { 
                            var inputValue = rec.inputValue; 
                            var boxLabel = rec.boxLabel; 
                            var checked = inputValue == value; 
                            var name =  view.id+"_Grdi_Column_Radio_"+record.data.Id+"_"+rowIndex; 
                            html += "<input name='" + name + "' type='radio' " + (checked ? "checked" : "") + "  colIndex='" + colIndex + "'  rowIndex='" + rowIndex + "' value='" + inputValue + "'/>" + boxLabel;
                        }); 
                        return html; 
                    },
                    tdCls: 'tdValign'
 
                }

  给表格加入事件

1
2
3
4
5
6
7
8
9
10
11
me.on('afterrender', function (grid, eOpts) {
          
          this.el.on('click', function (event) {
              var radio = event.getTarget('input[type="radio"]');
              if (radio) {
                  var rowIndex = radio.getAttribute("rowIndex");
                  var colIndex = radio.getAttribute("colIndex");
                  this.getStore().getAt(rowIndex).set('FeeModel',radio.value);
              }
          }, this);
      });

  表格全部代码:

复制代码
Ext.define('Yxd.view.FeeModelSet.ProjectGrid', {
    extend: 'Yxd.ux.BaseGridPanel',
    xtype: 'FeeModelSet_ProjectGrid',
    border: 0,
   initComponent: function () {
        var me = this;
        var store = Ext.create("Yxd.store.Project", {
            autoLoad: true

        });
     
        Ext.applyIf(me, {
            store: store,
            columns: [
               {
                   flex: 1,
                   dataIndex: 'Id',
                   text: 'Id',
                   hidden: true,

                   align: 'center'
               }, {
                   text: '序号',
                   xtype: 'rownumberer',
                   width: 50,
                   tdCls: 'tdValign',
                   align: 'center'
               },
                {
                    dataIndex: 'Name',
                    text: '项目名称',
                    flex: 1,
                    align: 'left',
                    tdCls: 'tdValign'

                }, {
                    dataIndex: 'FeeModel',
                    text: '收費模式',
                    flex: 1,
                    align: 'left',
                    radioValues: [{ "inputValue": "1", "boxLabel": "高級收費模式" }, { "inputValue": "2", "boxLabel": "简单收费模式" }, { "inputValue": "3", "boxLabel": "不收费模式" }],
                    renderer:function(value, metaData, record, rowIndex, colIndex, store, view) {  
                        var column = view.getGridColumns()[colIndex],  
                            html = '';  
                        Ext.each(column.radioValues, function(rec) {  
                            var inputValue = rec.inputValue;  
                            var boxLabel = rec.boxLabel;  
                            var checked = inputValue == value;  
                            var name =  view.id+"_Grdi_Column_Radio_"+record.data.Id+"_"+rowIndex;  
                            html += "<input name='" + name + "' type='radio' " + (checked ? "checked" : "") + "  colIndex='" + colIndex + "'  rowIndex='" + rowIndex + "' value='" + inputValue + "'/>" + boxLabel;
                        });  
                        return html;  
                    },
                    tdCls: 'tdValign'

                }]

        });

        me.callParent(arguments);
        me.on('afterrender', function (grid, eOpts) {
           
            this.el.on('click', function (event) {
                var radio = event.getTarget('input[type="radio"]');
                if (radio) {
                    var rowIndex = radio.getAttribute("rowIndex");
                    var colIndex = radio.getAttribute("colIndex");
                    this.getStore().getAt(rowIndex).set('FeeModel',radio.value);
                }
            }, this);
        });
     }
  
});
复制代码

 

posted @   沈阳晓东  阅读(1533)  评论(0编辑  收藏  举报
编辑推荐:
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
· 如何调用 DeepSeek 的自然语言处理 API 接口并集成到在线客服系统
点击右上角即可分享
微信分享提示