PDA

View Full Version : Selection Model Error/Issue



dkordik
14 Jun 2011, 1:08 PM
Seems like the newest release (4.0.2) has broken a grid's selection model. In previous releases I could run the code


var sm = gridPanel.getSelectionModel();
sm.select(0);

This worked fine, the first row of the grid was selected. Now when I run the above code with version 4.0.2 I receive the following error: 'Store' is null or not an object

Anyone having the same issue or have a work-around?

My grid is simple and defined as the following (in case anyone was curious)


var gridPanel = Ext.create('Ext.grid.Panel', {
region:'center',
autoScroll: true,
id: 'myGrid',
columnLines:true,
flex: 1,
store: myStore,
columns: [
{
id :'period',
text : 'Period',
width : 55,
sortable : true,
dataIndex: 'period'
},
{
text : 'Total Purchases',
width : 85,
sortable : true,
dataIndex: 'total',
id: 'total',
renderer: Ext.util.Format.usMoney
},
{
text : 'Contract Purcahses',
width : 90,
sortable : true,
dataIndex: 'contractsales',
id: 'contractsales',
renderer: Ext.util.Format.usMoney
},
{
text : 'Non-Contract Purchases',
width : 95,
sortable : true,
dataIndex: 'noncontractsales',
id: 'noncontractsales',
renderer: Ext.util.Format.usMoney
},
{
text : 'Contract Ratio%',
width : 90,
sortable : true,
dataIndex: 'contractper',
id: 'contractper',
renderer: perc
},
{
text : 'Non-Contract Ratio%',
width : 95,
sortable : true,
dataIndex: 'noncontractper',
id: 'noncontractper',
renderer: perc
},{
text : 'DSO',
width : 50,
sortable : true,
dataIndex: 'dso',
id: 'dso'
},{
text : 'Fill Rate%',
width : 50,
sortable : true,
dataIndex: 'fillrate',
id: 'fillrate',
renderer: perc
},{
text : 'Order Count',
width : 75,
sortable : true,
dataIndex: 'ordercount',
id: 'ordercount'
},{
text : 'Order Lines',
width : 70,
sortable : true,
dataIndex: 'linecount',
id: 'linecount'
},{
text : 'Fill Lines',
width : 50,
sortable : true,
dataIndex: 'filllines',
id: 'filllines'
}
],
tbar:[{
text: 'Print Account Overview Report',
iconCls: 'reports',
cls: 'medline-label',
handler : function(){
Ext.app.dashboard.sortField = "";
detailsWin.hide();
printReport();
}
}]});

brown-cow
20 Jun 2011, 10:12 AM
I'm having the same issue after upgrading to 4.0.2a.

It happens at the same point as you described. My code looks like this:



gridAnswerInput.show();

answers.each(function(a){
answerDetailStore.add(a);
});

gridAnswerInput.getSelectionModel().select(0);


This worked fine before the upgrade. Now it seems to break in the selection model class in the "doSelect" method:



doSelect: function(records, keepExisting, suppressEvent) {
var me = this,
record;

if (me.locked) {
return;
}
if (typeof records === "number") {
records = [me.store.getAt(records)]; // <---- me.store is null here now
}
if (me.selectionMode == "SINGLE" && records) {
record = records.length ? records[0] : records;
me.doSingleSelect(record, suppressEvent);
} else {
me.doMultiSelect(records, keepExisting, suppressEvent);
}
},


Any workarounds and/or suggestions greatly appreciated.

Thanks!

ValterBorges
20 Jun 2011, 10:34 AM
I have a grid defined with

selModel : {
selType: 'checkboxmodel',
mode: 'MULTI',
allowDeselect:true,
injectCheckbox:'first'
}

and in the after store load event I do, the following and it's working.

var grid = Ext.getCmp('MyGridIdHere'); //Note to change this to QueryCmp per best practices.
var sm = grid.getSelectionModel();

//probably want an if here to check if there are rows also.
sm.select(0);

brown-cow
20 Jun 2011, 12:16 PM
Hey @dkordik, I noticed that both of our Grids live in a Border layout. I'm wondering if this release note entry (4.0.2a) has anything to do with it? Anyone?


New Features
[EXTJSIV-1936] - Make ComboBox work better with existing filters
[EXTJSIV-2093] - Stateful Tree & Grid components do not fully restore state when in Border Layout


Thanks

brown-cow
21 Jun 2011, 8:37 AM
For anyone still stuck on this, I found a workaround / solution to this issue. After reading a few other posts on the forum, it became clear that you cannot select a grid row before it's rendered and made visible, but doing so after seems to work fine. Not sure, but this seems to be something that changed in release 4.0.2a.

Anyways, whether all that is 100% accurate or not, I was able to get my grid selections working if I did it after the grid was rendered and visible.

Another tidbit that I found interesting was that while selecting rows with selectionModel is still available, selections can also be done using the grid's view. So both of these lines essentially do the same thing.



myGrid.getSelectionModel().select(0);

myGrid.getView().select(0);


Hope that helps someone.

dkordik
22 Jun 2011, 8:08 AM
Thanks, I think that should do it...I'll give it a shot!

dkordik
23 Jun 2011, 5:37 AM
my only issue with this, is that I created a dashboard, with a grid behind the scenes. So the grid is feeding the dashboard, and you can view the grid via a pop-up, but when the dashboard loads, no gris is viewed, but I need to be able to select through rows to interactively change the data feeding the dashboard....