PDA

View Full Version : [FIXED][2.2.x/3.0] bug for selectRow in RowSelectionModel



mmusson
11 Sep 2008, 2:23 PM
If you select multiple rows in a grid and then click your mouse on one of those rows without holding down Ctrl or Shift, the expected behavior would be for the other selected rows to clear and the grid be left with just the newly clicked row as the selected row.

Right now, the final mouse click is ignored.

selectRow in RowSelectionModel begins with the following check:


if(this.locked || (index < 0 || index >= this.grid.store.getCount()) || this.isSelected(index)) return;I think this should be rewritten as:


if(this.locked || (index < 0 || index >= this.grid.store.getCount()) || (keepExisting && this.isSelected(index))) return;

mjlecomte
11 Sep 2008, 2:29 PM
search........already reported.

mmusson
11 Sep 2008, 2:35 PM
I did search for this bug using 'RowSelectionModel selectRow keepExisting' but didn't find any posts. Good to know that it has already been found. Thanks.

mjlecomte
11 Sep 2008, 2:59 PM
It's tough searching for bugs I think. I didn't search but kind of remembered from memory. Track it back from here. If you agree it's a DUP then you might want to edit your post to say [DUP].

http://extjs.com/forum/showthread.php?p=218000#post218000

mmusson
11 Sep 2008, 3:54 PM
Yeah, successfully searching for bugs in the forum is hit or miss. Looking at those links and where they lead, all the discussion is about the CheckboxSelectionModel and drag+drop causing problems.

The problem described above occurs for a vanilla grid without drag+drop so it doesn't seem like a dup at least for those posts.

Condor
3 Mar 2009, 4:04 AM
*** Bump ***

Isn't it about time we fix this behaviour? It's simply not what users expect of singleSelect:false.

Most obvious usecase:
1. Create a grid with a RowSelectionModel with singleSelect:false.
1. Selected all records (select first record, shift-click last record).
2. Click any row (without pressing ctrl).
Result: Nothing happens -- the user has no idea how to deselect the records.
Expected result: All records get deselected except the clicked row.

The complete override is:

Ext.override(Ext.grid.RowSelectionModel, {
selectRow : function(index, keepExisting, preventViewNotify){
if(this.isLocked() || (index < 0 || index >= this.grid.store.getCount()) ||
(keepExisting && this.isSelected(index))) return;
var r = this.grid.store.getAt(index);
if(r && this.fireEvent("beforerowselect", this, index, keepExisting, r) !== false){
if(!keepExisting || this.singleSelect){
this.clearSelections();
}
this.selections.add(r);
this.last = this.lastActive = index;
if(!preventViewNotify){
this.grid.getView().onRowSelect(index);
}
this.fireEvent("rowselect", this, index, r);
this.fireEvent("selectionchange", this);
}
}
});

@mjlecomte: This is not a duplicate as far as I could see. The only other thread (http://www.extjs.com/forum/showthread.php?t=52553) mentioning this problem is marked as a duplicate of this thread.

Condor
12 May 2009, 5:42 AM
Moving this thread to the 3.0 Bugs section hoping it will get more attention there...

evant
12 May 2009, 7:08 AM
Agreed. In fact I thought I fixed this a while back. Must have never committed it.

jnicora
10 Sep 2009, 7:30 AM
Did this ever get fixed?

Condor
10 Sep 2009, 11:42 AM
Yes, it's fixed in 2.3 and 3.0.0.

elderotaku
1 Oct 2009, 12:48 PM
if I have Drag and Drop Enabled does it stop this from working. it does not appear to be working for me?

THanks

wp.joju
18 Feb 2010, 8:25 PM
is the keepExisting parameter default as false? was it default to true before like in v2.2?

Rob_mac
2 Jun 2010, 6:19 AM
I'm encountering a problem with the selected rows not clearing when one of them is clicked in ExtJS 3.2.1. It seems to be tied up with the use of the enableDragDrop config. To see the problem, simply add singleSelect: false, enableDragDrop: true to the Ext.grid.GridPanel invocation within the examples\grid\array-grid.js example shipped with ExtJS, as follows:



// create the Grid
var grid = new Ext.grid.GridPanel({
store: store,
columns: [
{id:'company',header: 'Company', width: 160, sortable: true, dataIndex: 'company'},
{header: 'Price', width: 75, sortable: true, renderer: 'usMoney', dataIndex: 'price'},
{header: 'Change', width: 75, sortable: true, renderer: change, dataIndex: 'change'},
{header: '% Change', width: 75, sortable: true, renderer: pctChange, dataIndex: 'pctChange'},
{header: 'Last Updated', width: 85, sortable: true, renderer: Ext.util.Format.dateRenderer('m/d/Y'), dataIndex: 'lastChange'}
],
stripeRows: true,
autoExpandColumn: 'company',
height: 350,
width: 600,
title: 'Array Grid',
// config options for stateful behavior
stateful: true,
stateId: 'grid',
singleSelect: false,
enableDragDrop: true
});


When enableDragDrop is false, however, the selections seem to get cleared as expected.

There is more code involved to fully implement the drag-drop but this example illustrates the problem with the selections not clearing.

Is this intended behaviour when drag-drop is enabled?

gjuggler
29 Jun 2010, 11:05 PM
Hi Rob_mac,

I've had similar problems with the Ext RowSelectionModel. It seems like someone put this together hastily, without paying much attention to the highly expected standard behavior of multiple selection grids (open up any file browser in any OS and you can easily test out the expected keyboard & mouse behavior -- they *all* act the same!).

My solution was to override RowSelectionModel to fix various things. See the following Gist: http://gist.github.com/458337

It's got more stuff in there than your issue alone... For example, I added an 'afterselectionchange' event which only fires after the completion of an entire selection user interaction (so we don't have to catch 50 events when the user selects 50 rows in one click!), and started fixing up the keyboard behavior too (though I think that could still use some work).

Anyway, it's not pretty but it's there in case anyone finds these overrides useful.

Cheers,
Greg

Rob_mac
30 Jun 2010, 12:37 AM
Thanks Greg, looks like that will be a great help!

davidsanderson
28 Jul 2010, 6:08 AM
Wait, how is this fixed? This still occurs in 3.2.1.

gjuggler
28 Jul 2010, 6:33 AM
Sometimes it's easier to roll your own than to wait for a fix!

A proper selection model has both a 'cursor' and an 'anchor' position, which are (mostly) independent of each other. The current RowSelectionModel from Ext doesn't maintain separate state for each position.

Instead of continuing to hack around with the built-in selection model, I decided to build a new one. It hasn't been thoroughly tested outside of our program, but the mouse & keyboard behavior feels much more 'right' to me and the aforementioned bug is gone (that issue on its own is a pretty quick fix).

http://github.com/wash/paperpile/blob/master/catalyst/root/js/import/selectionmodel.js

--greg

davidsanderson
28 Jul 2010, 11:31 AM
How do you use this greg?

gjuggler
28 Jul 2010, 11:55 AM
What we do is include an instance of the BetterRowSelectionModel in the 'selModel' property of the grid's initial configuration object:

Ext.apply(grid, {
selModel: new Ext.ux.BetterRowSelectionModel()
});

I should warn you, the code I linked to is pretty raw -- I haven't tested it outside of our application, so don't be surprised if things break a bit! I tried to keep things pretty generic, though.

Cheers,
greg

Jamie Avins
28 Jul 2010, 2:28 PM
Just so everyone knows, For ExtJS 4.0 - SelectionModel is being moved into it's own class to be shared across all classes that use selection (grid, dataview, list, tree, etc.) where we resolved all these issues including drag and drop and keyboard navigation and many other long standing problems.