PDA

View Full Version : Getting the selected records of a grid with a CellModel



mono blaine
28 Oct 2011, 4:06 AM
I'm just getting tired of these bugs in ExtJS 4. Don't you guys perform a basic testing on certain components before you relese anything?

Instead of explaning the details I'll just skip to the resolution part:

The method onSelectChange is marked as abstract in class Ext.selection.Model. However, the class Ext.selection.CellModel does not implement this method, therefore nothing happens when you click on a cell of a grid.

mitchellsimoens
28 Oct 2011, 5:59 AM
Ext.selection.CellModel uses the onCellSelect and onCellDeselect and this is where it fires the select and deselect events. Tested in 4.0.7 and these events do fire.

mono blaine
28 Oct 2011, 9:07 AM
Ext.selection.CellModel uses the onCellSelect and onCellDeselect and this is where it fires the select and deselect events. Tested in 4.0.7 and these events do fire.

Yes, of course they do fire. But you don't get it. I didn't say "the select event isn't fired". The problem is indeed within the implementation of onCellSelect and onCellDeselect. If you had actually looked at the source code you would've seen it right away.

Here, I'll save you the trouble and debug it myself:

Here is the onCellSelect method of Ext.selection.CellModel:


onCellSelect: function (position) {
var me = this,
store = me.view.getStore(),
record = store.getAt(position.row);

me.doSelect(record);
me.primaryView.onCellSelect(position);
// TODO: Remove temporary cellFocus call here.
me.primaryView.onCellFocus(position);
me.fireEvent('select', me, record, position.row, position.column);
}

Everything is fine here, except when the method doSelect is called: (defined in the superclass Ext.selection.Model)


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

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

In my case, the selectionMode is "SINGLE", so doSingleSelect is called:


doSingleSelect: function (record, suppressEvent) {
var me = this,
changed = false,
selected = me.selected;

if (me.locked) {
return;
}
// already selected.
// should we also check beforeselect?
if (me.isSelected(record)) {
return;
}

function commit() {
me.bulkChange = true;
if (selected.getCount() > 0 && me.doDeselect(me.lastSelected, suppressEvent) === false) {
delete me.bulkChange;
return false;
}
delete me.bulkChange;

selected.add(record);
me.lastSelected = record;
changed = true;
}

me.onSelectChange(record, true, suppressEvent, commit);

if (changed) {
if (!suppressEvent) {
me.setLastFocused(record);
}
me.maybeFireSelectionChange(!suppressEvent);
}
}

As you can see from the line


me.onSelectChange(record, true, suppressEvent, commit);

the method onSelectChange needs to be implemented by the subclass of Ext.selection.Model so that the inline function commit could be invoked and we could get some records when we call getSelection, getLastSelected, or sth like that from the Ext.selection.CellModel instance.

I hope I made myself clear. If that's the case, you would see this thread is not a question, it is indeed a BUG. A terrible one.

skirtle
28 Oct 2011, 10:26 AM
Yes, of course they do fire. But you don't get it. I didn't say "the select event isn't fired". The problem is indeed within the implementation of onCellSelect and onCellDeselect. If you had actually looked at the source code you would've seen it right away.

You're entitled to be frustrated with bugs in the framework but this is unnecessarily rude. Your initial post didn't properly explain what problem you had found. Mitchell spent some time trying to help you and you've just slapped him across the face. Please refrain from personal abuse on the forums.


I hope I made myself clear. If that's the case, you would see this thread is not a question, it is indeed a BUG. A terrible one.

This is the Q&A forum. You don't appear to have a question. There is a bugs forum for reporting bugs. I'm sure your thorough breakdown of the problem would be much appreciated.

mono blaine
28 Oct 2011, 10:47 AM
You're entitled to be frustrated with bugs in the framework but this is unnecessarily rude. Your initial post didn't properly explain what problem you had found. Mitchell spent some time trying to help you and you've just slapped him across the face. Please refrain from personal abuse on the forums.

Well, I actually stated what the problem is in the title of the thread, but yes, I should've mentioned it within the post, too.


This is the Q&A forum. You don't appear to have a question. There is a bugs forum for reporting bugs. I'm sure your thorough breakdown of the problem would be much appreciated.

I know it is Q&A forum now, but the thread was in the bugs forum initially. Someone moved it here.

And yes, I was a little rude. Sorry about that. ExtJS is great; I was just a little too exposed to its bugs for the past week.

skirtle
28 Oct 2011, 11:10 AM
I know it is Q&A forum now, but the thread was in the bugs forum initially. Someone moved it here.

I see. The moderators spend a lot of time moving threads around because so many are started in the wrong place. There's a template for submitting bugs; you'll find it in a sticky thread at the top of the bugs forum. A lot of it is mindless boilerplate but if you follow that template your bug is much more likely to be dealt with promptly. It also reduces the chance that a moderator will mistake it for a question.

mitchellsimoens
29 Oct 2011, 5:37 AM
Already a bug filed

complex14
5 Mar 2012, 2:08 AM
cellmodel in EXTjs 4 seem lame and very hard to use

errd
29 May 2013, 3:07 AM
Is there any progress on this issue? I've tried to use CellModel and selection mode MULTI and SIMPLE, but it seems that it doesn't work. I'm using ExtJS 4.2.0 for now.
Here is the code:

this.grid = Ext.create('Ext.grid.GridPanel', {
selModel: new Ext.selection.CellModel({
mode: 'SIMPLE'
}),
multiSelect: true,
...
});