简体   繁体   English

在Flex中的DataGrid中用null替换NaN值

[英]Replacing a NaN value with null in DataGrid in flex

<mx:AdvancedDataGridColumn headerText="{Mlc.curr.get('column 1')}" dataField="datafield1" labelFunction="getTotalQty"/>


private function getTotalQty(inData:Object, inCol:AdvancedDataGridColumn):String
        {
            return (isNaN(inData.qty)?"":inData.qty);
        }

currently this returns an empty data grid cell for each cell. 当前,这将为每个单元返回一个空的数据网格单元。 irrespective of whether the cell is NaN or has a number in it. 无论单元格是NaN还是其中有数字。

the datagrid is passed several objects, object 0 has NaN and thus returns a null box, object 1 has value 70 and still returns a null box. datagrid传递了几个对象,对象0具有NaN,因此返回一个空框,对象1具有值70,并且仍然返回一个空框。

inData is a generic object; inData是通用对象; which probably means that qty is also untyped; 这可能意味着qty也没有输入。 as it is not a default property on object. 因为它不是对象的默认属性。 That would be why it fails the isNaN test. 这就是为什么它无法通过isNaN测试。 Try casting inData to your custom object or casting inData.qty to a Number. 尝试将inData强制转换为自定义对象,或将inData.qty强制强制转换为Number。

Something like this: 像这样:

private function getTotalQty(inData:Object, inCol:AdvancedDataGridColumn)
{
            var qtyAsNumber : Number = Number(inData.qty);
            return (isNaN(qtyAsNumber)?"":qtyAsNumber.toString());
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM