2014-01-09 146 views
2

我的表單中有一個帶有CheckboxSelectionModel的網格面板。我正在使用ExtJs 3.4。這是我的網格面板。CheckboxSelectionModel ExtJs中的網格:無法選中網格面板中的複選框,選中標題複選框時將檢查所有行

var selectModel = new Ext.grid.CheckboxSelectionModel(); 

var drop_pick_grid = new Ext.grid.GridPanel({ 
store : dropPickGridStore, 
cm : new Ext.grid.ColumnModel([ selectModel, { 
    sortable : true, 
    header : "Drop/Pick Loc", 
    dataIndex : 'locationName', 
    width : 170, 
    renderer : function(value, metaData, record, rowIndex, 
      colIndex, store) { 
     var refColor = record.data.tourTypeColor; 
     //console.log(record); 
     metaData.attr = 'style="background-color:' + refColor + ';"'; 
     return record.get('locationName'); 
    } 
}, { 
    header : "Town/City", 
    sortable : true, 
    dataIndex : 'city', 
    width : 120 
}, { 
    header : "Address", 
    sortable : true, 
    dataIndex : 'addr', 
    width : 170 
}, { 
    header : "EST.Un/Load Time", 
    sortable : true, 
    dataIndex : 'estimatedTime', 
    width : 100 
} ]), 
sm : new Ext.grid.CheckboxSelectionModel(), 
//width : 570, 
//height : 390, 
autoHeight : true, 
autoWidth : true, 
frame : true, 
iconCls : 'icon-grid', 
renderTo : document.body 
}); 

此網格使用Json從postgresql數據庫加載。

var dropPickGridStore = new Ext.data.JsonStore({ 
fields : [ { 
    name : 'locationCode' 
}, { 
    name : 'locationName' 
}, { 
    name : 'city' 
}, { 
    name : 'addr' 
}, { 
    name : 'estimatedTime' 
}, { 
    name : 'tourTypeColor' 
} ], 
root : 'dropPickLoc', 
idProperty : 'locationCode', 
//autoDestroy : true, 
autoLoad : true, 

proxy : new Ext.data.HttpProxy({ 
    url : "http://" + host + ":" + port + "/" + projectName + "/" 
      + "PendingDropPicks" 

}), 
reader : { 
    type : 'json', 
    root : 'dropPickLoc' 
    //idProperty : 'locationName', 
}, 
}); 

網格成功加載。問題是我無法檢查網格中的複選框,但它可以通過單擊標題複選框來選擇所有行。爲什麼它不能單獨檢查每一行。

回答

4

您必須在columnsselModel配置中使用相同的選擇模型對象。在這裏,您創建了兩個不同的Ext.grid.CheckboxSelectionModel實例。

替換此行:

sm: new Ext.grid.CheckboxSelectionModel(), 

有了這個:

sm: selectModel, 
+0

rixo,我已經嘗試過這一點。但後來我無法檢查網格的任何複選框。我只能挑選標題複選框 – Rose18

+0

這應該起作用。但爲什麼這對我不起作用 – Rose18

+0

在我的dropPickGridStore中是否有任何錯誤 – Rose18

相關問題