数据网格AS3 - 如何保存编辑细胞变量 [英] datagrid as3 - How to save edited cells to variables

查看:192
本文介绍了数据网格AS3 - 如何保存编辑细胞变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作就是拉从早期在这个过程中获得的变量的信息数据网格。我需要能够编辑overpaidAmount列。我已经锁定了,只是我需要用户输入一个所有列,但一旦他们补充的资料,我怎么分配回一个变量?到处找在线和不能找到任何针对这一具体问题。

I'm working on a datagrid that is pulling information from variables obtained earlier in the process. I need to be able to edit the overpaidAmount column. I've locked down all columns except the one that I need an input from the user, but once they add the information, how do I assign it back to a variable? Looked everywhere online and cant find anything for this specific issue.

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);

任何帮助是AP preciated。

Any help is appreciated.

推荐答案

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

Ok so I came up with a solution, whether it's the best way to do this - probably not:(

我要创建哪些举行了小区的信息在连续几个动态文本字段,一旦我点击它们。然后,我创建了一个输入的文本字段,以显示我想更新变量。新增更新按钮下面的听众和做的伎俩。只需要添加一些code刷新一次数据网格的值进行了更新。

I had to create a few dynamic text fields which held the information from the cells in a row once I click on them. Then I created an input text field to display the variable I wanted to update. Added an update button with the following listener and that did the trick. Just needed to add some code to refresh the datagrid once a value was updated.

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);
}

这篇关于数据网格AS3 - 如何保存编辑细胞变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆