Extjs4.2 GridPanel中顯示單選按鈕

效果:如上圖。javascript

代碼:其中須要顯示單選按鈕的列html

{
                    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'

                }

  給表格加入事件java

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

  表格所有代碼:app

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);
        });
     }
  
});
相關文章
相關標籤/搜索