Formatting a Flex DataGrid control using a custom
来源:互联网 发布:淘宝小二介入怎么取消 编辑:程序博客网 时间:2024/06/05 10:23
The following example formats a column in a Flex DataGrid and uses a custom item renderer to color the text red in a cell if a price is below $0. If the item is greater than $0, the test is displayed in black. The price column is also formatted using a custom label function, which uses a CurrencyFormatter, and finally, the data grid column uses a custom sort function to properly sort numeric columns.
Full code after the jump.
<?xml version="1.0" encoding="utf-8"?><!-- http://blog.flexexamples.com/2007/08/20/formatting-a-flex-datagrid-control-using-a-custom-item-renderer/ --><mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" verticalAlign="middle" backgroundColor="white"> <mx:Script> <![CDATA[ import mx.controls.dataGridClasses.DataGridColumn; import mx.utils.ObjectUtil; private function price_labelFunc(item:Object, column:DataGridColumn):String { return currencyFormatter.format(item.@price); } private function price_sortCompareFunc(itemA:Object, itemB:Object):int { return ObjectUtil.numericCompare(itemA.@price, itemB.@price); } ]]> </mx:Script> <mx:XML id="itemsXML"> <items> <item name="Item 1" price="1.32" /> <item name="Item 2" price="-12.23" /> <item name="Item 3" price="4.96" /> <item name="Item 4" price="-0.94" /> </items> </mx:XML> <mx:Style> .centered { text-align: center; } </mx:Style> <mx:CurrencyFormatter id="currencyFormatter" precision="2" useNegativeSign="false" /> <mx:DataGrid id="dataGrid" dataProvider="{itemsXML.item}"> <mx:columns> <mx:DataGridColumn dataField="@name" headerText="Name:" headerStyleName="centered" /> <mx:DataGridColumn dataField="@price" headerText="Price:" textAlign="right" headerStyleName="centered" labelFunction="price_labelFunc" sortCompareFunction="price_sortCompareFunc" itemRenderer="PriceLabel" /> </mx:columns> </mx:DataGrid></mx:Application>
PriceLabel.as
package { import mx.controls.Label; import mx.controls.listClasses.*; public class PriceLabel extends Label { private const POSITIVE_COLOR:uint = 0x000000; // Black private const NEGATIVE_COLOR:uint = 0xFF0000; // Red override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void { super.updateDisplayList(unscaledWidth, unscaledHeight); /* Set the font color based on the item price. */ setStyle("color", (data.@price <= 0) ? NEGATIVE_COLOR : POSITIVE_COLOR); } }}
View source is enabled in the following example.
COPY FROM : http://blog.flexexamples.com/2007/08/20/formatting-a-flex-datagrid-control-using-a-custom-item-renderer/
- Formatting a Flex DataGrid control using a custom
- Resizing a Flex DataGrid control using the rowCount property
- Removing items from a Flex DataGrid control using the DragManager class
- Creating a custom label function on a Flex LineChart control’s category axis
- Building a custom Flex preloader
- LINQ to SQL系列Part 9-Using a Custom LINQ Expression with the control
- zz - transcript of Defining and Using Shared Resources in a Custom Control Library
- Use RSClientPrint control in a custom application
- Custom Draw items inside a ListView Control
- Using a Context Menu on a Control
- Animating Pie Slices Using a Custom CALayer
- 53. Using a Custom Admin URL
- Opening nodes in a Flex Tree control using the expandItem() method
- Using a Custom Action to Create a Database During Installation
- Using a Custom Action to Create a Database During Installation
- Using a Custom Action to Create a Database During Installation
- Using a Custom Action to Create a Database During Installation
- Using a Custom Action to Create a Database During Installation
- Groovy Tip 20 “as”关键字的用法
- 8.25
- 连载最后一期:大学生求职七大昏招(二十)缺少职业素养(5)
- 北京奥运会圆满结束了
- org.apache.maven.plugins:maven-archetype-plugin does not exist
- Formatting a Flex DataGrid control using a custom
- 再谈数据库性能提升及搜索优化之一 - 服务器的选择及相关配置
- 加速动态网站"MySQL"索引的分析和优化
- 如何快速给现有表添加一个自增字段
- 对 java.nio.ByteBuffer 的粗浅理解
- 高效SQL
- Observer’s Protocol Decodes
- MS Windows Workstation Service NetrWkstaUserEnum() 0day Memory Allocation Remote DoS Exploit # Bug discovered by h07
- Changing the default skins on a Button control in Flex