views:

1487

answers:

1

I have a functional datagrid that responds to itemClick events. Everything works, except that it also triggers the itemClick event when the headers are clicked. So instead of sorting the grid data they trigger the event which changes the state. I want to only have the click event respond to the rows being clicked, not the headers.

I have googled everywhere and dug through my books and every example i've seen seems to work, so i'm wondering what i am doing wrong here:

<mx:Script>
     <![CDATA[

      [Bindable]
      public var acPrograms:ArrayCollection;



      private function showGameDetail(event:ListEvent):void {
       var programEvent:ProgramsEvent = new ProgramsEvent(ProgramsEvent.SHOW_DETAIL);
       programEvent.selectedProgram = TvPrograms( event.currentTarget.selectedItem );
       dispatchEvent(programEvent);

       currentState = "details";
      }  

     ]]>
    </mx:Script>     
    <mx:DataGrid id="gamesGrid" height="270" dataProvider="{acPrograms}"
      itemClick="showGameDetail(event);">
      <mx:columns>
       <mx:DataGridColumn headerText="Date" dataField="dateOutput" width="90" />
       <mx:DataGridColumn headerText="Time" dataField="startTime" width="70" />
       <mx:DataGridColumn headerText="Title" dataField="subTitle" width="360" />
       <mx:DataGridColumn headerText="Channel" dataField="channel" width="80" />
       <mx:DataGridColumn headerText="Provider" dataField="provider" width="100" />
      </mx:columns>
     </mx:DataGrid>

Edit:

The real issue here was my cache settings. I was working with a cached version that had a click event instead of an itemClick. So the click event responds to all clicks on the grid and the itemClick does as desired, all I needed to to was turn off my cache. Bonehead on my part, But thanks for the help.

+2  A: 

how about adding the following in your event handler?

if (event.rowIndex < 0) 
  return;
Sean Clark Hess
thanks, this worked like a charm! but it turns out the main key was i had a cached template that had a click event instead of itemClick so your solution would work had i had click and the cache turned off LOL With the cache off the itemClick works fine. Thanks Though!
ethyreal