软硬度:数字的DataGrid列格式 [英] Flex: DataGrid column formatting of numbers

查看:113
本文介绍了软硬度:数字的DataGrid列格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在DataGrid中的一列格式化一些数字。我得到一个错误在我的简单测试程序,当我运行它下面。所有我见过的例子都列数据是字符串。有没有办法用数字做呢?如何修改低于code格式化检查值?

 < XML版本=1.0编码=UTF-8&GT?;
< MX:应用
    的xmlns:FX =htt​​p://ns.adobe.com/mxml/2009
    XMLNS:S =库://ns.adobe.com/flex/spark
    的xmlns:MX =库://ns.adobe.com/flex/mx>

< FX:脚本>
    <![CDATA [
        [可绑定]
        公共变种检查:阵列=新阵列(1000000.2222,0,1000);

        私有函数myLabelFunction(项目:阵列,列:一个DataGridColumn):字符串{
                VAR结果:字符串;
                结果= myFormatter.format(项目);
                返回结果;
        }
    ]]≥
< / FX:脚本>

< FX:声明>
    &所述氏:的NumberFormatter的id =myFormatter
                       的fractionalDigits =2
                       decimalSeparator =。
                       使用groupingSeparator =,
                       useGrouping =真
                       的NegativeNumberFormat =0
                       />
< / FX:声明>

< MX:DataGrid的ID =DG1的dataProvider ={}检查>

    < MX:列>
        < MX:一个DataGridColumn的dataField =检查HEADERTEXT =检查
                           的labelFunction =myLabelFunction/>
    < / MX:列>

< / MX:数据网格>

< / MX:用途>
 

解决方案
  1. 更改过滤函数签名(项目对象

    私有函数myLabelFunction(项目:对象,列:一个DataGridColumn):字符串

  2. 删除的dataField =检查从列。

I'm trying to format some numbers in a column of a DataGrid. I'm getting an error in my simplified test program below when I run it. All the examples I've seen so far have column data that are strings. Is there a way to do it using numbers? How to modify the code below to format the checking values?

<?xml version="1.0" encoding="utf-8"?>
<mx:Application 
    xmlns:fx="http://ns.adobe.com/mxml/2009" 
    xmlns:s="library://ns.adobe.com/flex/spark" 
    xmlns:mx="library://ns.adobe.com/flex/mx">

<fx:Script>
    <![CDATA[       
        [Bindable]
        public var checking:Array = new Array(1000000.2222, 0, 1000);

        private function myLabelFunction(item:Array, column:DataGridColumn):String {    
                var result:String;
                result = myFormatter.format(item);
                return result;
        }
    ]]>
</fx:Script>

<fx:Declarations>
    <s:NumberFormatter id="myFormatter"
                       fractionalDigits="2" 
                       decimalSeparator="."
                       groupingSeparator=","
                       useGrouping="true"
                       negativeNumberFormat="0"
                       />
</fx:Declarations>

<mx:DataGrid id="dg1" dataProvider="{checking}" >

    <mx:columns>
        <mx:DataGridColumn dataField="checking" headerText="Checking" 
                           labelFunction="myLabelFunction" />
    </mx:columns>

</mx:DataGrid>

</mx:Application>

解决方案

  1. Change filter function signature (item should be Object)

    private function myLabelFunction(item:Object, column:DataGridColumn):String

  2. Remove dataField="checking" from column.

这篇关于软硬度:数字的DataGrid列格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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