PDA

View Full Version : Ext.grid.GridPanel : CheckBoxSelectionModel



enedhilwen
16 Nov 2009, 8:55 PM
Dear all:

In a custom grid I like to be able to pre-select the first entry, if the total size of elements is only 1. Therefore, I was installing a CheckBoxSelectionModel on to grid, and a listener on the backing stores "load" event.

Some code next.

In the wrapping class, the model gets defined:

lastValuesSelectionModel: new Ext.grid.CheckboxSelectionModel({ header: ' ', singleSelect: true }),


Within the grid, the selModel gets attached& the column added:


colModel: new Ext.grid.ColumnModel({
defaults: { sortable: false },
selModel: this.lastValuesSelectionModel,
columns: [
this.lastValuesSelectionModel,
{ header: 'Time', dataIndex: 'mtime'},


In the wrapping panels initComponent method, I'm installing the listener:


Ext.ux.MucMeterValuesChart.superclass.initComponent.call(this);

Ext.ComponentMgr.get('lastValuesDataGrid').getStore().on('load', this.lastValuesGridLoaded, this);


And here is where it starts to break:


lastValuesGridLoaded: function(store, records, options) {
grid = Ext.ComponentMgr.get('lastValuesDataGrid');
if(records.length === 1) {
grid.getSelectionModel().selectFirstRow();
} else {
grid.getSelectionModel().clearSelections();
}
},



I can access all fields without problems, so I don't see a scoping problem
Doing a getSelected() call on the selection Model works also. By ID even.

When keeping the code, Firebug will report this error:


Error: this.grid is undefined
Source File: http://localhost:9090/app-muc/jslib/nc/ext/ext-all-debug.js
Line: 63537


So, I suspect that the init function for the selModel isn't called properly.

To overcome this issue, I was trying to write this line within the initComponent method. So that the grid gets assigned manually:


Ext.ux.MucMeterValuesChart.superclass.initComponent.call(this);

this.lastValuesSelectionModel.grid = Ext.ComponentMgr.get('lastValuesDataGrid');

Ext.ComponentMgr.get('lastValuesDataGrid').getStore().on('load', this.lastValuesGridLoaded, this);


Unluckily not successful as well.

Anybody of you went into this before? Maybe I'm binding, listening to early.. any hint is appreciated.

Thanks everyone,
Seb

PeterDK
1 Jun 2010, 3:14 AM
Did you find any solution to this problem, I am experiencing a similar problem now