I was never a huge fan of Flash Components back in the day, now I find that they are essential in building flash applications. Here is an example of using the Data Grid Component. In this example we add data to the grid by applying the addItem method. You can also add data via an xml file or an array. To get this to work you simply just add the DataGrid component to your library. I just accomplished this by dropping the component out of the component panel, placing it on the stage, then deleting it. This automatically adds it to the library.
You should roll your mouse over the table below to demonstrate the methods of the DataGrid Component.
package
{
import flash.display.MovieClip;
import fl.controls.DataGrid;
import fl.data.DataProvider;
public class DataGridExample extends MovieClip
{
private var myDataGrid:DataGrid;
private var myDP:DataProvider;
public function DataGridExample()
{
var myDP:DataProvider = new DataProvider();
myDP.addItem({ID:"01", Name:"Morgan", Email:"Morgan@blah.com", Web:"manewc.com"});
myDP.addItem({ID:"02", Name:"Ashley", Email:"Ashley@blah.com", Web:"google.com"});
myDP.addItem({ID:"03", Name:"Michael", Email:"Michael@blah.com", Web:"yahoo.com"});
var myDataGrid:DataGrid = new DataGrid();
myDataGrid.addColumn("ID");
myDataGrid.addColumn("Name");
myDataGrid.addColumn("Email");
myDataGrid.addColumn("Web");
myDataGrid.dataProvider = myDP;
myDataGrid.width = 530;
myDataGrid.move(10, 10);
addChild(myDataGrid);
}
}
}
Hi Morgan,
I am working on an AS3 project the uses the datagrid component and I am populating it at runtime with data from an external XML file. What I was looking to do was to somehow enable the user to search the grid. Just create a text field on the page and have it accept users input text to search for a string.
The data grid contains a list of applications ( about 300 or so ) and the users want to be able to search it.
I have surfed the web on and off for about a week and I am not finding much out there about using and manipulting data in a flash datagrid.
I was looking for some suggestions as to how could create a search box to search the grid.
Thanks so very much. Your time is much appreciated.
Phil Toth.
I remember seeing a demo somewhere about searching xml content, I’ll have to dig that up from my archives. Are you using Flex for this application?
Is there any way to change font color of a row on over? It seems like a simple thing but I cannot find any examples of it being done in a datagrid.
Hello Randy, Sorry for the delayed response.. just got back from vacation.. Interesting thought on the rollover color issue, I think I will search around and see if I can come up with a demo.. I have a feeling that one way to do it is with CSS.
-Morgan
Out of curiosity is there a way to detect what box is clicked and then pull the data from that box?
for use with something like:
System.setClipboard();
the search function is on adobe’s developer page samples.
http://www.adobe.com/devnet/flash/quickstart/datagrid_pt3/
dataGrid can be produce by either external class document and drag drop component with frame script,, but how to manage or control datagrid using external as, but the component it self has been in the stage with instance name… !?
thanks before