2011-10-11 42 views
5

Tôi cần nhóm radio trong lưới extjs. Tôi có thể có radiogroup làm trình soạn thảo nhưng người dùng muốn trực tiếp chọn tùy chọn từ radio.Nhóm Radio trong ExtJS Editor Lưới/Lưới

ví dụ: O yes O no O có thể

thay vì phải có theo mặc định và khi họ chọn ô, nó sẽ được chuyển thành nhóm radio (như cách mạng lưới trình soạn thảo hoạt động), họ muốn hành vi mặc định như tùy chọn này. (Họ không muốn thả xuống)

Trả lời

2

Tôi tạo ra một thành phần nhóm radio:

Ext.define('Ext.ux.grid.column.RadioGroupColumn', { 
    extend: 'Ext.grid.column.Column', 
    alias: 'widget.radiogroupcolumn', 

    /* author: Alexander Berg, Hungary */ 
    defaultRenderer: function(value, metadata, record, rowIndex, colIndex, store, view) { 
     var column = view.getGridColumns()[colIndex]; 
     var html = ''; 
     if (column.radioValues) { 
      for (var x in column.radioValues) { 
       var radioValue = column.radioValues[x], radioDisplay; 
       if (radioValue && radioValue.fieldValue) { 
        radioDisplay = radioValue.fieldDisplay; 
        radioValue = radioValue.fieldValue; 
       } else { 
        radioDisplay = radioValue; 
       } 
       if (radioValue == value) { 
        html = html + column.getHtmlData(record.internalId, store.storeId, rowIndex, radioValue, radioDisplay, 'checked'); 
       } else { 
        html = html + column.getHtmlData(record.internalId, store.storeId, rowIndex, radioValue, radioDisplay); 
       } 
      } 
     } 
     return html; 
    }, 

    getHtmlData: function(recordId, storeId, rowIndex, value, display, optional) { 
     var me = this, clickHandler, readOnly; 
     var name = storeId + '_' + recordId; 
     var clickHandler; 
     if (me.readOnly) { 
      readOnly = 'readonly'; 
      onClick = ''; 
     } else { 
      readOnly = ''; 
      onClick = "onclick=\"this.checked=true;Ext.StoreManager.lookup('" + storeId + "').getAt(" + rowIndex + ").set('" + me.dataIndex + "', '" + value + "');\"'"; 
     } 
     return ' ' + display + ' '; 
    } 
});

Cách dùng 1:

{ 
    "xtype" : "radiogroupcolumn", 
    "text" : "Radio Group Test", 
    "width" : 160, 
    "radioValues" : ["yes", "no", "maybe"], 
    "dataIndex" : "radio" 
}

Cách dùng 2:

{ 
    "xtype" : "radiogroupcolumn", 
    "text" : "Radio Group Test", 
    "width" : 160, 
    "radioValues" : [{ 
      "fieldValue" : "yes", 
      "fieldDisplay" : "Yes" 
     }, { 
      "fieldValue" : "no", 
      "fieldDisplay" : "No" 
     }, { 
      "fieldValue" : "maybe", 
      "fieldDisplay" : "Maybe" 
     } 
    ], 
    "dataIndex" : "radio" 
}
+0

Với ext-js 4.1 điều này không hoạt động, đó là phiên bản của ext-js bạn đã thử nghiệm mã này với? – Gab

Các vấn đề liên quan