PDA

View Full Version : simpleSelect on xtype:grid with selModel: RowSelectionModel -> Possible?



Redsandro
11 Jun 2011, 9:11 AM
I have a grid with an implied default selModel of RowSelectionModel, and implied default setting singleSelect = false, causing you to be able to select multiple rows of data.

In a gridView, the same would be done using multiSelect = true, which also gives you the optional feature called simpleSelect = true. This makes it so you aren't required to hold ctrl for a multi-selection.

Is there an easy way to have simpleSelect for a grid with RowSelectionModel? It's not in the documentation, but I was hoping there is a relatively simple trick to enable this. I'd reckon this is a popular feature and I'm probably missing something, but I can't figure it out using google.

skirtle
12 Jun 2011, 2:34 AM
I don't know of anything simple but here's something that seems to work:


new Ext.grid.GridPanel({
...
listeners: {
rowmousedown: function(grid, rowIndex, ev) {
var selModel = grid.getSelectionModel();

if (ev.button !== 0 || selModel.isLocked()){
return;
}

if (selModel.isSelected(rowIndex)) {
selModel.deselectRow(rowIndex);
}
else {
selModel.selectRow(rowIndex, true);
}

return false;
}
}
});

Redsandro
12 Jun 2011, 6:10 AM
Thank you good Sir! This does pretty much exactly the trick.

I didn't know rowmousedown was a proper event. I did try to look up all available events; the API documentation is awesome, but I have not yet succeeded in securing a list of available events.

I hope this simple extension will be available in ExtJS 4. Haven't yet migrated to 4 because I figured migrating existing ExtJS 3 code is more work than just keep using 3. For now.

skirtle
12 Jun 2011, 7:12 AM
That event is definitely documented:

http://dev.sencha.com/deploy/ext-3.4.0/docs/?class=Ext.grid.GridPanel

Scroll right down to the bottom... third row up.

Redsandro
12 Jun 2011, 9:03 AM
You are right. My bad.