Select to view content in your preferred language

Fire Datagrid item_click event

994
2
Jump to solution
08-27-2014 08:14 AM
RebeccaWatson
Deactivated User


I'm having some issues getting an event to fire programmatically. I have two datagrids. I execute an identifyTask from a click on the map and populate myGrid with the results. When I click on a record in myGrid, the dataGridClickEvent function is run which populates detailGrid with more detailed information. This all runs fine, but I would like it so that if there is only one result from the identifyTask, the dataGridClickEvent function runs automatically to populate detailGrid.

This is the code I am using, but detailGrid is still not being populated unless I physically click on the record in myGrid.

//ArrayCollection for my results

initDG = new ArrayCollection(DGArray);

//if the ArrayCollect has only one result  

if (initDG.length == 1)

{ 

myGrid.dispatchEvent(new ListEvent(ListEvent.ITEM_CLICK, false, false,0,0));

}

I have also tried:

dataGridClickEvent(new ListEvent(ListEvent.ITEM_CLICK, false, false ,0,0));

Can anyone tell me where I am going wrong?

Thanks.

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Rebecca,

   Is your detailGrid receiving the event and just failing because of some condition in your eventhandler? Have you put a trace in the detailGrid event handler? Working with programmatic event firing can be difficult. Have you just considered an additional function that the one result in the identify would call to populate the detailGrid?

View solution in original post

0 Kudos
2 Replies
RobertScheitlin__GISP
MVP Emeritus

Rebecca,

   Is your detailGrid receiving the event and just failing because of some condition in your eventhandler? Have you put a trace in the detailGrid event handler? Working with programmatic event firing can be difficult. Have you just considered an additional function that the one result in the identify would call to populate the detailGrid?

0 Kudos
RebeccaWatson
Deactivated User


Thank you Robert. I thought that I must be doing the event firing wrong so I didn't look closely enough at what the dataGridClickEvent handler was doing. The event is firing, but the dataGridClickEvent function uses event.currentTarget.selectedItem to ascertain which discipline the results are for and then shows a selection of attributes that are relevant to that discipline. When I fire the event programmatically, the event.currentTarget doesn't seem to be set so the discipline variable and all the attributes were not being assigned. So I have added myGrid.selectedIndex = 0;  into the if statement (shown in my first post) and changed my dataGridClickEvent function as follows and it seems to have done the trick:

  

private function dataGridClickEvent(event:ListEvent):void 

{

// var discipline was being assigned like this

// var discipline:String = event.currentTarget.selectedItem.Disc;

//now it's being assigned like this

var discipline:String = myGrid.selectedItem.Disc;

aMap = new Object();

dpArray = new Array();

     switch(discipline)

{

          case "Water":

          // attributes were being assigned like this

          //aMap["Location"] = event.currentTarget.selectedItem.Loc;

          // now attributes are being assigned like this

          aMap["Location"] = myGrid.selectedItem.Loc;

          //then numerous other attributes are assigned

     for (var pkey:String in aMap)

          {

               dpArray.push({label:pkey, data:aMap[pkey]});

          }

     initDP = new ArrayCollection(dpArray);

break;

//etc for the other disciplines

Thanks for pointing me in the right direction again.

0 Kudos