2014-11-03 144 views
0

我正在使用Ext.grid.CheckboxSelectionModel和Ext.grid.GridPanel来显示带复选框列的网格。 但是当我点击行复选框也会被选中。关于选择ext js grid中的行复选框被选中

我想复选框不应该被选中,而选择网格的行。 有什么办法可以做到这一点。

下面是我的代码片段。

var cboxSelModel =new Ext.grid.CheckboxSelectionModel({ 
       checkOnly : true, 
       width:100, 
       header: defaultVal, 
       id: 'test', 
       locked: true, 
       singleSelect: true, 
       listeners: { 
        rowselect: function (sm, rIndex, keepExisting, record) {    
         uncheckIndex = -1; 
         cIndex =rIndex; 
         updateDefaultValue(); 
        }, 
        rowdeselect: function (sm, rIndex, keepExisting, record) {    
         cIndex = -1; 
         uncheckIndex =rIndex; 
         updateDefaultValue(); 
        } 
       } 
     }); 

grid = new Ext.grid.GridPanel({ 
       id:'grid', 
       width:'99%', 
       border:true, 
       store: store, 
       tbar: toolBar, 
       autoscroll: false, 
       height :'100px', 
       autoHeight :false, 
       sm: cboxSelModel, 
       cm :cm, 
       height:150, 
       layout: 'fit', 
       stateful: true, 
       stateId: 'grid', 
       autoScroll:true, 
       enableColumnResize : false, 
       enableColumnMove : false, 
       viewConfig:{ 
        forceFit:true, 
        scrollOffset:0 
       }, 
       autoFitColumns: true, 
       listeners: { 
        afterrender: function() { 
         setSelectedRows(); 
         var store=grid.getStore(); 
         if(store.data.length > 0){ 
          Ext.getCmp('btnSort').setDisabled(false); 
          Ext.getCmp('btnSort').setIconClass('bmcSort'); 
         } 
        },delay: 1000, 
        cellClick :function(iView, iCellEl, iColIdx, iRecord, iRowEl, iRowIdx, iEvent){ 
          storeindex = iCellEl; 
          var record = grid.store.getAt(iCellEl); 
          var dValue=record.get('displayValue'); 
          var sValue=record.get('storedValue'); 
          var dataArray = getListData(); 
          sValue=dataArray[iCellEl][1]; 
          sValue = Ext.util.Format.htmlDecode(sValue); 
          dValue = Ext.util.Format.htmlDecode(dValue);       
          document.getElementById(InputPageComp.ComponentVars.storedValue).value=sValue; 
          document.getElementById(InputPageComp.ComponentVars.displayValue).value=dValue; 
          document.getElementById('addbtn_id').style['display']= 'none'; 
          document.getElementById('updatebtn_id').style['display']= 'block'; 
          Ext.getCmp('btnRemove').setDisabled(false); 
          Ext.getCmp('btnRemove').setIconClass('bmcDeleteSLT'); 
          grid.getSelectionModel().selectRow(iCellEl); 

         } 

       }   
     }); 
+0

集'CHECKONLY:TRUE'复选框选择模型。请参阅[文档](http://docs.sencha.com/extjs/4.2.2/#!/api/Ext.selection.CheckboxModel-cfg-checkOnly) – MMT 2014-11-03 08:00:20

+0

我已经这样做了,但这并不奏效。可以检查代码 – 2014-11-03 09:18:08

回答

0

变种SM = Ext.create( 'Ext.selection.CheckboxModel',{ CHECKONLY:真 });

我测试过了。它应该工作