AS3 Quick Tips: Datagrid: How to Extract Data From a Single Cell in a DataGrid Component

Recently i’ve been messing about with Flash’s built in components, for the most part they are self explanatory and easy enough to figure out from Adobes docs. Recently however i have had to use editable DataGrids in a form type scenario, I could create and display a DataGrid fine, but when it came to collect the data from it? I was completely stumped, Mainly because DataGrids utilize loads of other classes, which can be very confusing.

So without any further words that you’ll no doubt skip :P … heres a function that will return the data of the targeted cell.

function returnCellData(dataGrid:DataGrid, rowIndex:int, columnIndex:int):String
{
	var cellData:String = dataGrid.columns[columnIndex].itemToLabel(dataGrid.getItemAt(rowIndex));
	return cellData;
}

I’ve included an example for download here:

Hope this helped!
Peace Out

Tags: , , , , ,

  • Pat Keller

    Thank you for sharing this! I’ve been pulling my hair out trying to get this one — and I’ve been coding for over 30 years. Honestly, to do something so straightforward and obviously necessary for the component to well-function should not be so complex. This should be a method of the component. Thank you!

  • http://www.bigtallbill.co.uk Bill Nunney

    yeah i know what you mean! this freaking datagrid has me pulling out my hair every odd day. Right now i’m trying to style the heading text on columns, still havent got it yet…

  • Andrew

    Hey I’ve been trying to get this to work but it returns undefined. I took it out of the function as well to try. I am wondering if it might be the characters in the title that are causing issue.

    My code imports a CSV into a datagrid and pops the headers at the top automatically.

  • Mike Nakos

    Yeah, but it’s another way to get the data of the grid.
    Say that your DataGrid pulls data from an ArrayCollection with name [dArr] (attribute on DataGrid declaration –> source={dArr}).
    You know the selected row of the grid ex. DGrid.selectedIndex, so you get the data of the cell like this:
    dArr[DGrid.selectedIndex]["name_of_a_collection_property"]

  • Juan Esteban

    THANK YOU!! me ahorraste muchos dolores de cabeza, gracias por compartir

  • Essex_london

    yey thank you >_<

  • Essex_london

    yey thank you >_<