2012-05-29 95 views
2

我有EditorGridPanel,網格的ColumnModel包含TextField,ComboBox和CheckBox。 編輯TextField或ComboBox後,會觸發包含有關編輯字段詳細信息的「afteredit」事件。 當我檢查/取消選中CheckBox字段時,沒有任何事件提供關於哪個CheckBox按下的任何細節。如何從網格中檢查CheckBox獲取詳細信息?

+0

您是使用roweditor還是celleditor? – Geronimo

回答

3

選擇模型呈現一列複選框,可以切換爲選中或取消選中網格中的行。

嘗試在複選框選擇模型上應用偵聽器。

文檔:Ext.selection.CheckboxModel-event-selectionchange

參考:example

+0

CheckboxSelectionModel沒有文本標題,不能放置在網格列中的特定位置。 –

+0

嘗試設置'injectCheckbox:Number/Boolean/String'來設置複選框列位置http://docs.sencha.com/ext-js/4-0/#!/api/Ext.selection.CheckboxModel-cfg-injectCheckbox – MMT

+0

使用extjs 2.2:/沒有injectCheckbox屬性 –

1

Ext.ux.CheckColumn使用checkchange事件。這給了rowIndex。

編輯

如果在2.2做更多的發展,我會建議你升級。但是,如果你不能,你總是可以嘗試添加覆蓋,或延長Ext.ux.CheckColumn以包含更新版本的事件。我相信這個代碼必須調整到與2.2兼容,但這裏有一個重寫的例子來包含所需的事件 - 我意識到我不確定2.2是否有Ext.override方法,您將不得不檢查您的文檔(checkchange代碼直接來自4.1 API):

Ext.override(Ext.ux.CheckChange, { 
    constructor: function() { 
     this.addEvents(
      /** 
      * @event beforecheckchange 
      * Fires when before checked state of a row changes. 
      * The change may be vetoed by returning `false` from a listener. 
      * @param {Ext.ux.CheckColumn} this CheckColumn 
      * @param {Number} rowIndex The row index 
      * @param {Boolean} checked True if the box is to be checked 
      */ 
      'beforecheckchange', 
      /** 
      * @event checkchange 
      * Fires when the checked state of a row changes 
      * @param {Ext.ux.CheckColumn} this CheckColumn 
      * @param {Number} rowIndex The row index 
      * @param {Boolean} checked True if the box is now checked 
      */ 
      'checkchange' 
     ); 
     this.callParent(arguments); 
    }, 

    /** 
    * @private 
    * Process and refire events routed from the GridView's processEvent method. 
    */ 
    processEvent: function(type, view, cell, recordIndex, cellIndex, e) { 
     var me = this, 
      key = type === 'keydown' && e.getKey(), 
      mousedown = type == 'mousedown'; 

     if (mousedown || (key == e.ENTER || key == e.SPACE)) { 
      var record = view.panel.store.getAt(recordIndex), 
       dataIndex = me.dataIndex, 
       checked = !record.get(dataIndex); 

      // Allow apps to hook beforecheckchange 
      if (me.fireEvent('beforecheckchange', me, recordIndex, checked) !== false) { 
       record.set(dataIndex, checked); 
       me.fireEvent('checkchange', me, recordIndex, checked); 

       // Mousedown on the now nonexistent cell causes the view to blur, so stop it continuing. 
       if (mousedown) { 
        e.stopEvent(); 
       } 

       // Selection will not proceed after this because of the DOM update caused by the record modification 
       // Invoke the SelectionModel unless configured not to do so 
       if (!me.stopSelection) { 
        view.selModel.selectByPosition({ 
         row: recordIndex, 
         column: cellIndex 
        }); 
       } 

       // Prevent the view from propagating the event to the selection model - we have done that job. 
       return false; 
      } else { 
       // Prevent the view from propagating the event to the selection model if configured to do so. 
       return !me.stopSelection; 
      } 
     } else { 
      return me.callParent(arguments); 
     } 
    }, 
}); 
+0

我使用的是extjs 2.2,並且在Ext.ux.CheckColumn中沒有「checkchange」事件 –

相關問題