-1

I've been having trouble setting the item renderer of a Spark DataGrid in CSS and then I remembered the compiler creates a class factory for it.

This CSS does not work:

.myGrid {
    itemRenderer: ClassReference("myItemRenderer");
}

but declaring it inline it does:

<s:DataGrid itemRenderer="myItemRenderer" />

I found this setStyle code and put it in the constructor but it doesn't work:

    public function DataGrid() {
        super();

        setStyle("itemRenderer", new ClassFactory(myItemRenderer));
    }

I've created a new control and I want to use my custom renderer as default. So all the styles are set in the defaults.css.

1.21 gigawatts
  • 16,517
  • 32
  • 123
  • 231
  • 1
    You can't set an itemrenderer in CSS, this only works via the property of the datagrid component as in your working example. If you want to avoid setting it for every datagrid in your application you could define an own skin for your datagrid and define your custom itemrenderer there – Philarmon Feb 08 '16 at 09:36
  • OK. I'm using a custom skin. I'll set it there. – 1.21 gigawatts Feb 08 '16 at 10:54

1 Answers1

0

I can't set a class factory in CSS for this property. I think the property needs to be a IFactory and defined as a style.

I can set an item renderer with the DataGrid. I can set it in the constructor using:

public function DataGrid() {
    super();

    itemRenderer = new ClassFactory(myItemRenderer);
}

or in the DataGrid skin:

<s:Scroller id="scroller" minViewportInset="1" hasFocusableChildren="false" height="100%">
    <!--- @private -->
    <s:Grid id="grid" itemRenderer="MyGridItemRenderer">

    </s:Grid>                    
</s:Scroller>
1.21 gigawatts
  • 16,517
  • 32
  • 123
  • 231