Access DataField value in Itemrenderer when submitting to Database

611 views Asked by At

I'm really stuck on this one. I have setup an Itemrenderer in a Datagrid which manages a DateField. Users can enter a date and other values directly in the datagrid. When they click 'submit', I want to populate a row in a database and I have setup a service for this. A row is created in the db with all values from the datagrid as expected however the date is not populated despite users having entered a value. Below is a code snippet:

Datagrid

<s:GridColumn dataField="datf" headerText="Period From" rendererIsEditable="true">
<s:itemRenderer>
  <fx:Component>
       <s:GridItemRenderer dataChange="updateRenderer()">
            <fx:Script>
                 <![CDATA[
                           public function updateRenderer():void {
                                periodFrom.text = outerDocument.dtf1.format(data.datf);
                           }

                           private function dateField_labelFunc(item:Date):String {
                                return outerDocument.dtf1.format(item);
                           }
                 ]]>
            </fx:Script>
                 <mx:DateField horizontalCenter="0" verticalCenter="0" width="90%" id="periodFrom" labelFunction="dateField_labelFunc"/>
       </s:GridItemRenderer>
  </fx:Component>

Handler

protected function createBillResult_resultHandler(event:ResultEvent):void
        {
            var dataProvider = itemsDg.dataProvider;
            var item = null;

            for (var i:int = 0; i < dataProvider.length; i++){
                item = dataProvider.getItemAt(i);
                trace(item.datf);<!--WHAT SHOULD GO HERE-->
                billItems.lnid = item.lnid;
                billItems.days = item.days;
                billItems.ratu = item.ratu;
                createBillItemsResult.token = billingService.createBillItems(billItems);
            }
        }

I would have thought that I can access the value from the itemrenderer using the dataField property like I do with the other items although these are not itemrenderers, but trace(item.datf) just returns 'undefined'. Am I using the wrong syntax?

Brian

1

There are 1 answers

1
Amy Blankenship On

You don't have a function in your itemRenderer that transfers the data back into the data object. However, DateField implements IDataRenderer and IDropInListItemRenderer, so my suspicion is that this will work as expected if you remove the GridItemRenderer wrapper. It seems like they've removed the labelFunction from spark datagrid (oddly, it has a dataTipFunction), so you'll probably need to extend DateField slightly in the way you've extended GridItemRenderer to make it work.


Edit to answer further question look at What is the replacement for labelFunction in Spark DataGrid?