Skip to main content
Kristtee
Known Participant
January 7, 2013
Question

how to setup a click even in DataGrid?

  • January 7, 2013
  • 2 replies
  • 545 views

Hi there!

I have a very simple DG that loads local xml data, then i am trying to add a click event to the items. on clicking a list item it should take to a web site. Here is the code. It is now working. Sure you can guide me, please.

--------------------------

import fl.data.DataProvider;

import fl.controls.dataGridClasses.DataGridColumn;

import fl.events.ListEvent;

mydg.move(15, 50);

mydg.setSize(530, 230);

var col_name:DataGridColumn = new DataGridColumn("titl");

col_name.headerText = "Title";

mydg.addColumn(col_name);

var col_job:DataGridColumn = new DataGridColumn("cat");

col_job.headerText = "category";

mydg.addColumn(col_job);

mydg.columns[0].width = 330;

mydg.columns[1].width = 200;

var leadData_xml:XML;

var dp:DataProvider = new DataProvider();

var urlRequest:URLRequest = new URLRequest("xleadata.xml");

var urlLoader:URLLoader = new URLLoader();

urlLoader.addEventListener(Event.COMPLETE, urlLoader_complete);

urlLoader.load(urlRequest);

function urlLoader_complete(evt:Event):void {

    leadData_xml = new XML(evt.target.data);

          //trace(leadData_xml.toXMLString());

          mydg.dataProvider = new DataProvider(leadData_xml);

          mydg.addEventListener(ListEvent.ITEM_CLICK, cHandler);

}

function cHandler(e:ListEvent):void{

          var leadpath:String = e.item.data;

          trace(leadpath.toString());

}

///////////////// xml /////////////////

<?xml version="1.0" encoding="UTF-8"?>

<leadata>

          <lead>

                    <titl>AS Examples</titl>

                    <cat>Code Samples</cat>

                    <lnk>http://actionscriptexamples.com/</lnk>

          </lead>

          <lead>

                    <titl>Flex Examples</titl>

                    <cat>Code Samples</cat>

                    <lnk>http://blog.flexexamples.com/</lnk>

          </lead>

          <lead>

                    <titl>GotoandLearn</titl>

                    <cat>Tutorials</cat>

                    <lnk>http://www.gotoandlearn.com/</lnk>

          </lead>

</leadata>

-----------------------------------------

Thanks

kristtee

This topic is closed to new replies. Start a new post to keep the conversation going.

2 replies

kglad
Community Expert
Community Expert
January 7, 2013

use:

function cHandler(e:ListEvent):void{

  

navigateToURL(new URLRequest(e.item.lnk));

}

Kristtee
KristteeAuthor
Known Participant
January 7, 2013

Hi Kglad

Thank you appreciate your help. I added the code as you have told. When testing , it worked first time. then it doesnot work anymore. Also I tryied to open the lnk into a new tab in FFox / Crome/IE. it does not work anymore. I wonder what is happening? Please guide me.

Thanks

kristtee