Reputation: 1633
I have a spark datagrid with selectionMode="multipleRows"
.
I have three columns in the datagrid.
I don't want the row selection to happen when the user's click falls on the third column of a row.
The row selection should happen only when one of the first two columns is clicked.
How do I achieve this? There is a selectionChanging
event for the datagrid, but the GridSelectionEvent
object received in the handler does not seem to provide any information about the column on which the click happened.
Thanks!
Upvotes: 0
Views: 2289
Reputation: 419
I know it's 13 years old, but I have same issue today, here how I done :
protected function dataGrid_itemClickHandler(e:GridSelectionEvent):void {
var mouseX:Number = dataGrid.mouseX;
mouseX += dataGrid.scroller.horizontalScrollBar.value;
var lastPosX:Number = 0;
var posX:Number = 0;
for (var i:int=0; i<dataGrid.columns.length; i++){
posX += dataGrid.grid.getColumnWidth(i);
if ((mouseX > lastPosX) && (mouseX< posX)){
break;
}
lastPosX += dataGrid.grid.getColumnWidth(i);
}
//now i is the column index cliqued
var dc:GridColumn = dataGrid.columns[i];
}
Big hack but it's working
Upvotes: 0
Reputation: 1633
I figured this out myself. I am not sure if this is a bug in the spark DataGrid. The following is definitely a hack and not clean.
In the grid_mouseDownHandler
function in the DataGrid.as
file, there is a line:
const columnIndex:int = isCellSelection ? event.columnIndex : -1;
This line is causing the columnIndex
to be set as -1
if the selectionMode
of the DataGrid
is anything other than GridSelectionMode.SINGLE_CELL
or GridSelectionMode.MULTIPLE_CELLS
. As I mentioned in the original question, I need my datagrid to have a selectionMode
of GridSelectionMode.MULTIPLE_ROWS
.
I sub-classed the DataGrid and re-implemented the grid_mouseDownHandler
(basically copy-pasted the whole function). I changed only the above line to always assign the columnIndex
to event.columnIndex
.
(I also had to copy some more functions which were referenced by the grid_mouseDownHandler
over to my sub-class because those functions were protected or mx_internal. (toggleSelection
, extendSelection
, isAnchorSet
)
Then, in the selectionChanging
event handler, I could just do the following:
if( 2 == event.selectionChange.columnIndex ) { event.preventDefault(); }
I realize that this is not a clean solution, but it is the best I could think of. Maybe someone can suggest a better solution?
Upvotes: 0