ketan
ketan

Reputation: 19341

Get value of editable GridColumn in flex

I have one datgrid with no. of columns like:

<s:DataGrid id="cpDataGrid" dataProvider="{arrList}">
 <s:columns>
  <mx:ArrayList>
   <mx:source>
     <s:GridColumn headerText="Name" dataField="name" editable="false"/>
     <s:GridColumn headerText="Age" datafield="age" editable="false"/>
     <s:GridColumn headerText="Test" dataField="test" editable="false" />
     <s:GridColumn width="100" headerText="Result" dataField="result" >
  </mx:source>
  </mx:ArrayList>
 </s:columns>   
</s:DataGrid>

In the above datagrid result column is editable. I have make function when user done entering value in that column as following:

protected function onCreationCompleteHandler(event:FlexEvent):void
{
  cpDataGrid.addEventListener(GridItemEditorEvent.GRID_ITEM_EDITOR_SESSION_SAVE, onSave);               
}

private function onSave(event:GridItemEditorEvent):void
{
    var name:String = event.currentTarget.selectedItem.name;
}

Now, I will get name and other field value when edit end. But i need Result text. Means Whatever user entered text in that field.

Like suppose user enter 50 in result column then how can i got that value?
Any help will greatly appreciated.

Upvotes: 0

Views: 387

Answers (1)

Petr Hrehorovsky
Petr Hrehorovsky

Reputation: 1153

For spark.DataGrid you need to create custom class based on spark.DataGrid and override method endItemEditorSession. In it you can access DataGrid's property itemEditorInstance.

If you would use mx.DataGrid, you could use DataGridEvent.ITEM_EDIT_END event in combination with itemEditorInstance property of DataGrid.

// register listener
cpDataGrid.addEventListener(DataGridEvent.ITEM_EDIT_END, onItemEditEnd);
...
// listener
private function onItemEditEnd(event:DataGridEvent):void {
    // at this point itemEditorInstance is still available, so you can get entered value from it
    // if itemEditorInstance is TextInput
    var enteredValue:String = TextInput(cpDataGrid.itemEditorInstance).text;
}

Upvotes: 1

Related Questions