Getting itemRenderer position in an Advanced dataGrid
I was working on a project that required me to replicate MS Access type functionality, in Flex. One of those tasks was clicking into a cell in the datasheet view and knowing what column I selected, so that I could change that column’s datatype. I also have to know which cell specifically was clicked so that I can pass that data to the rest of the application.
Easier said than done. That is until Jonathan Branam came to my rescue on twitter.
@jwilker listData implement IDropInListItemRenderer – cast it to AdvancedDataGridListData how much do you need to know?
A little tweaking on my renderer, and what I had been struggling for the better part of a day, was solved, just like that.
My renderer implements IDropInListItemRenderer, and my listData() function translates listData into an adv dataGridListData
public function set listData(value:BaseListData):void
_listDataGrid = AdvancedDataGridListData(value);
cellText.text = _listDataGrid.label;
cellText.name = “DataSheet_Grid_Cell_” + _listDataGrid.columnIndex.toString() + “_” + _listDataGrid.rowIndex.toString();
Then inside my main component, my clickHandler can get the various values i need to do what I need to do (that sounds funny, I know)
private function handleClick( evt:MouseEvent ):void
var tmpColVo:ColumnVO = TableVO(_model.selectedDatabaseVO.selectedObjectVO).acColumns.getItemAt(evt.currentTarget.selectedCells.columnIndex) as ColumnVO;
_model.selectedDatabaseVO.dataSheetVO.selectedColumnVO = tmpColVo;
_model.selectedDatabaseVO.dataSheetVO.selectedColumnIndex = evt.currentTarget.selectedCells.columnIndex;
_model.selectedDatabaseVO.dataSheetVO.selectedRowIndex = evt.currentTarget.selectedCells.rowIndex;
_model.selectedDatabaseVO.dataSheetVO.selectedRowVo = evt.currentTarget.dataProvider.getItemAt(evt.currentTarget.selectedCells.rowIndex) as RowVO;
var selectionEvent:DataSheetSelectionEvent = new DataSheetSelectionEvent(true);
_model.selectedDatabaseVO.dataSheetVO.selectedColumnHeader = TableVO(_model.selectedDatabaseVO.selectedObjectVO).acColumns.getItemAt(evt.currentTarget.selectedCells.columnIndex).name;
The upside was that I was wrapping up my role in the project and was dreading not being able to walk away with no “I couldn’t finish” type things. Which was nice. My renderer is below. It was just a simple POC approach to help another developer with his task, and serve my immediate need, since I had a dependency on that functionality from the renderer.
Props to Jonathan for a solution under 140 characters that saved my day!