R – How to style the each cell of Flex DataGrid

apache-flexcelldatagrid

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 hyperlink.

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

I searched, but of not much help..!!

Best Answer

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.

Related Topic