Search code examples
actionscript-3apache-flexflex4flex3flex4.5

Clear a cell in a DataGrid


I have an editable datagrid with a dataprovider which is basically Numbers. Is it possible to delete a value? When I do it it puts a 0 in that cell but I really need an empty value, like a Null or a NaN whose are going to be cleaned later with a labelFunction. BTW I also need the cells to keep the 0 if needed to. Thank you in advance.


Solution

  • Assign NaN to the value, and create a custom item renderer for your DataGrid:

    <?xml version="1.0" encoding="utf-8"?>
    <s:GridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
                        xmlns:s="library://ns.adobe.com/flex/spark"
                        xmlns:mx="library://ns.adobe.com/flex/mx"
                        clipAndEnableScrolling="true">
    
        <fx:Script>
            <![CDATA[
                override public function prepare(hasBeenRecycled:Boolean):void
                {
                    if (isNaN(data[column.dataField]))
                        lblData.text = "";
                    else
                        lblData.text = Number(data[column.dataField]).toFixed(2);
                }
            ]]>
        </fx:Script>
    
        <s:Label id="lblData"
                 top="9"
                 left="7" />
    
    </s:GridItemRenderer>