datagrid as3 - 如何将已编辑的单元格保存到变量

时间:2013-07-04 15:57:03

标签: actionscript-3 datagrid

我正在研究一个数据网格,它从过程中早先获得的变量中提取信息。我需要能够编辑overpaidAmount列。我已经锁定了所有列,除了我需要用户输入的列,但是一旦他们添加了信息,我该如何将它分配回变量?在网上到处查看,无法找到针对此特定问题的任何内容。

import fl.controls.DataGrid;
import fl.controls.ScrollPolicy;
import fl.data.DataProvider;
import fl.controls.dataGridClasses.DataGridColumn;

var col1:DataGridColumn = new DataGridColumn("Line");
var col2:DataGridColumn = new DataGridColumn("ServiceCode");
var col3:DataGridColumn = new DataGridColumn("BilledCharge");
var col4:DataGridColumn = new DataGridColumn("Paid");
var col5:DataGridColumn = new DataGridColumn("OverpaidAmount");

datagrid.addColumn(col1);
datagrid.addColumn(col2);
datagrid.addColumn(col3);
datagrid.addColumn(col4);
datagrid.addColumn(col5);

col1.editable = false;
col2.editable = false;
col3.editable = false;
col4.editable = false;

col1.minWidth = 40;
col2.minWidth = 80;
col3.minWidth = 80;
col4.minWidth = 80;
col5.minWidth = 130;

var myData:Array;

if ((majorPercentage1 == "---") || (majorPercentage1 == "000") || (majorPercentage1 == "   "))
{
    myData =  
    [
        {Line:"1", ServiceCode: cpt1, BilledCharge: charge1, Paid: basicPaid1, OverpaidAmount: overpaidAmount1},
        {Line:"2", ServiceCode: cpt2, BilledCharge: charge2, Paid: basicPaid2, OverpaidAmount: overpaidAmount2},
        {Line:"3", ServiceCode: cpt3, BilledCharge: charge3, Paid: basicPaid3, OverpaidAmount: overpaidAmount3},
        {Line:"4", ServiceCode: cpt4, BilledCharge: charge4, Paid: basicPaid4, OverpaidAmount: overpaidAmount4},
        {Line:"5", ServiceCode: cpt5, BilledCharge: charge5, Paid: basicPaid5, OverpaidAmount: overpaidAmount5}
    ];
}
else
{
    myData =  
    [
        {Line:"1", ServiceCode: cpt1, BilledCharge: charge1, Paid: majorPaid1, OverpaidAmount: overpaidAmount1},
        {Line:"2", ServiceCode: cpt2, BilledCharge: charge2, Paid: majorPaid2, OverpaidAmount: overpaidAmount2},
        {Line:"3", ServiceCode: cpt3, BilledCharge: charge3, Paid: majorPaid3, OverpaidAmount: overpaidAmount3},
        {Line:"4", ServiceCode: cpt4, BilledCharge: charge4, Paid: majorPaid4, OverpaidAmount: overpaidAmount4},
        {Line:"5", ServiceCode: cpt5, BilledCharge: charge5, Paid: majorPaid5, OverpaidAmount: overpaidAmount5}
    ];  
}
datagrid.dataProvider = new DataProvider(myData);

感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

好的,所以我想出了一个解决方案,无论是最好的方法 - 可能不是:(

我必须创建一些动态文本字段,一旦我点击它们就会从单元格中保存信息。然后我创建了一个输入文本字段来显示我想要更新的变量。添加了一个带有以下监听器的更新按钮,并且完成了这一操作。只需在值更新后添加一些代码来刷新数据网格。

function griditemselected (event:Event):void{
overPaid_txt.text = event.target.selectedItem.OverpaidAmount;
}

//Find the row number of the selected item so that we can update the correct overpaid amount
datagrid.addEventListener(ListEvent.ITEM_CLICK , gridItemSelected);
function gridItemSelected(e:ListEvent):void {
rowID = Number(e.rowIndex)+1;
}     

updated_btn.addEventListener(MouseEvent.CLICK, updateOverpaid);

function updateOverpaid(e:MouseEvent):void
{
//Update the selected line overpaidAmount       
switch (rowID)
{
    case 1:
    overpaidAmount1 = overPaid_txt.text;
    break;

    case 2:
    overpaidAmount2 = overPaid_txt.text;
    break;

    case 3:
    overpaidAmount3 = overPaid_txt.text;
    break;

    case 4:
    overpaidAmount4 = overPaid_txt.text;
    break;

    case 5:
    overpaidAmount5 = overPaid_txt.text;
    break;
}           
//Remove all the rows and refresh with new variable for overpaid amount
datagrid.removeAll();
datagrid.addItem(event1);
datagrid.addItem(event2);
datagrid.addItem(event3);
datagrid.addItem(event4);
datagrid.addItem(event5);
}