0
votes

I'm trying to implement a datagrid with footer as defined with this class :

https://github.com/ncdc/flex-footer-datagrid

It's working perfectly. Nevertheless in a second step I have tried to implement with this package an itemrenderer on one column in order to display the value with a specific style.

Here my code

        <footerDataGrid:FooterDataGrid
            id="dg_imActivity" width="100%" 
            dropEnabled="true"
            dragDrop="model.checkIfActivityExixts(event)"
            dataProvider="{grant!=null?model.activities.grantItems:null}" 
            editable="true"
            itemEditEnd="EditBudgetValue(event)"
            rowCount="{grant!=null?dg_imActivity.dataProvider.length + 2:6}"
            >

            <footerDataGrid:columns>
                <mx:DataGridColumn headerText="Title" dataField="title" showDataTips="true" dataTipField="title" editable="false"/>
                <mx:DataGridColumn headerText="Type" dataField="type" showDataTips="true" dataTipField="type" editable="false"/>
                <mx:DataGridColumn headerText="Pr. Area" dataField="prioAreaName" showDataTips="true" dataTipField="prioAreaName" editable="false"/>
                <mx:DataGridColumn headerText="Unit" dataField="unitName" showDataTips="true" dataTipField="unitName" editable="false">
                        <mx:itemRenderer>
                            <fx:Component>                                  
                                <mx:HBox paddingLeft="2" horizontalScrollPolicy="off">
                                    <fx:Script>
                                        <![CDATA[
                                            import mx.controls.Alert;
                                            import mx.states.SetStyle;

                                            override public function set data( value:Object ) : void {
                                                super.data = value;

                                                if( data.unitName != outerDocument.user.profile.organ.name ) {
                                                    setStyle("color",0xFF0000);
                                                    setStyle("fontWeight", "bold");
                                                }else{
                                                    setStyle("color",0xffffff);
                                                    setStyle("fontWeight", "normal");
                                                }

                                            }
                                        ]]>
                                    </fx:Script>
                                    <mx:Label text="{data.unitName}" width="100%"/>
                                </mx:HBox>
                            </fx:Component>
                        </mx:itemRenderer>


                </mx:DataGridColumn>
                <mx:DataGridColumn headerText="Value" dataField="budgetValue" id="budgetValue" showDataTips="true" dataTipField="budgetValue" editable="true"/>
            </footerDataGrid:columns> 

            <footerDataGrid:footer>
                <footerDataGrid:SummaryFooter>
                    <footerDataGrid:columns>
                        <footerDataGrid:SummaryColumn  label='Total'/>
                        <footerDataGrid:SummaryColumn />
                        <footerDataGrid:SummaryColumn />
                        <footerDataGrid:SummaryColumn />                                                        
                        <footerDataGrid:SummaryColumn operation='sum' precision='2'/>
                    </footerDataGrid:columns>
                </footerDataGrid:SummaryFooter>


                <footerDataGrid:SummaryFooter>
                    <footerDataGrid:columns>
                        <footerDataGrid:SummaryColumn label='Remaining Budget'/>
                        <footerDataGrid:SummaryColumn />
                        <footerDataGrid:SummaryColumn />
                        <footerDataGrid:SummaryColumn />                                                            
                        <footerDataGrid:SummaryColumn labelFunction='remainingBudgetActivity' dataColumn='{budgetValue}'/>
                    </footerDataGrid:columns>
                </footerDataGrid:SummaryFooter>

            </footerDataGrid:footer>
        </footerDataGrid:FooterDataGrid>

I obtain an error with the itemrenderer.

ReferenceError: Error #1069: Property unitName not found on mx.controls.dataGridClasses.DataGridColumn and there is no default value.

The abel is displayed without the style. All is correctly defined. Apparently the method set data() is correctly called, but it cannot retrieve the data object and I do not know the reason. Besides I have tried with a default datagrid and it's working.

Could you please tell me how to solve this problem? I need to use this package because I need to display footer in the datagrid.

1

1 Answers

0
votes

I do not why but with this package I have to add a test in order to see if the object property exists:

if( "unitName" in data){
    if( data.unitName != outerDocument.user.profile.organ.name ) {
        setStyle("color",0xFF0000);
        setStyle("fontWeight", "bold");
    }else{
        setStyle("color",0x000000);
        setStyle("fontWeight", "normal");
    }
}               

And now all is working. It was strange because with the default datagrid, no test was necessary.