views:

1218

answers:

1

I have a Flex DataGrid, which has some columns, i had put a item renderer, which makes all the elements in that column hyperlinked, i have a requirement, where i need to see the type of user, based on that i have to either enable or disable the hyper link.

Is there any good way , where i can get the style properties at the cell level...?

Thanks ...in advance..., i searched , but of not much help..!!

A: 

Bind the item renderer's data property (or set a listener) so that it disables the hyperlink when changed. The data property changes each time the cell receives new data to render.

Here are a couple possibilities.

class User {
  public var type:String;
}

<mx:Panel ...

  <mx:Component id="simple">
    <mx:Label styleName="{data.type}"></mx:Label>
  </mx:Component>

  <mx:Component id="userRenderer">
    <mx:Label dataChange="onChange(event)">
      <mx:Script>
        <![CDATA[
          private function onChange(event:FlexEvent) {
            // do something
          }
        ]]>
      </mx:Script>

    </mx:Label>
  </mx:Component>

  <mx:DataGrid ...>
    <mx:columns>
        <mx:DataGridColumn itemRenderer="userRenderer" />
    </mx:columns>
  </mx:DataGrid>
</mx:Panel>

With a minimal snippet of your code, the example might be more fitting, but you should be able to adapt this.

Chadwick
Chadwick, but one more thing , in onChange() , can we get hold of other row's data..? And also how to get hold of style properties...for the cell data..?
In the 'simple' component, I set the styleName of the component used to render the cell (a Label). In that example, you'll want to have a style in your css for each type of data. With the 'userRenderer' component you could do something more complex (like setting the 'enabled' attribute: `event.target.enabled = (data.type == 'goodType')` which would enable the Label for goodType and disable for all others. You can of course use any kind of component instead of Label and change whatever properties you wish.
Chadwick
@Santosh you cannot 'get hold of other row's data' nor do I think you should want to. The component will be rendered once for each cell (actually multiple instances are used, but that's not relevant) and each time, data is set appropriately. http://www.google.com/search?q=flex+datagrid+item+renderer
Chadwick