Change dataprovider data for spark data grid?

感情迁移 提交于 2019-12-13 04:35:29

问题


I have a data grid with editable property set to true. When I make changes to the data the data is not modified in the data provider. How can I apply the changes to the data provider? I am new to Flex, can anyone make suggestions on this?


回答1:


Hero is an example and I have tested it.

and you can see this doc http://livedocs.adobe.com/flex/3/html/help.html?content=celleditor_8.html

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" minWidth="955" minHeight="600" creationComplete="application1_creationCompleteHandler(event)">

<mx:Script>
    <![CDATA[
        import mx.controls.TextInput;
        import mx.events.DataGridEvent;
        import mx.events.FlexEvent;


        private var list:Array  = [];//source dataProvider

        protected function application1_creationCompleteHandler(event:FlexEvent):void
        {
            list.push({name:"aaaa"}, {name:"bbbb"});

            myDataGrid.dataProvider = list;
        }

        protected function myDataGrid_itemEditEndHandler(event:DataGridEvent):void
        {
            // TODO Auto-generated method stub
            var targetDataGrid:DataGrid = event.target as DataGrid;
            var newData:String = TextInput(targetDataGrid.itemEditorInstance).text;
            var label:String = event.dataField;

            //here according to target data type in list,you may force changing type of newData, like int(newData)
            var indexOfList:int = targetDataGrid.editedItemPosition.rowIndex;
            list[indexOfList][label] = newData;

        }

    ]]>
</mx:Script>

<mx:DataGrid id="myDataGrid" editable="true" itemEditEnd="myDataGrid_itemEditEndHandler(event)">
    <mx:columns>
        <mx:DataGridColumn  dataField="name" headerText="Name" editable="true" />
    </mx:columns>
</mx:DataGrid>



来源:https://stackoverflow.com/questions/17083853/change-dataprovider-data-for-spark-data-grid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!