Format the values of a column in the Table in Flex.
1. Problem background
Generally, the ratio shown in the table is as follows: Keep two decimal places and keep them up.
2. Implementation instance
<? Xml version = "1.0" encoding = "UTF-8"?> <S: 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 "width =" 100% "height =" 100% "fontSize =" 12 "fontFamily =" "> <s: layout> <s: basicLayout/> </s: layout> <fx: Script> <! [CDATA [import mx. collections. arrayCollection; import mx. events. flexEvent; [Bindable] // bind table data to private var gridArray: ArrayCollection = new ArrayCollection ([{week: "Monday", apple: "3676", rate: "0.7868 "}, {week: "Tuesday", apple: "4534", rate: "0.65454" },{ week: "Wednesday", apple: "6758", rate: "0.876454 "}, {week: "Thursday", apple: "9808", rate: "0.34224" },{ week: "Friday", apple: "6567", rate: "0.9876523 "}, {week: "Saturday", apple: "9000", rate: "0.566777 "},{ Week: "Sunday", apple: "4533", rate: "0.988787"}]);/*** format the ratio in the table */private function formatDataGrid (item: object, column: DataGridColumn): String {var temp: Number = item. rate; var data: String = dataFormatter. format (temp); return data;}]> </fx: Script> <fx: Declarations> <! -- Format the number --> <mx: NumberFormatter id = "dataFormatter" precision = "2" rounding = "up"/> </fx: Declarations> <mx: VBox width = "100%" height = "100%" paddingBottom = "10" paddingLeft = "10" paddingRight = "20" paddingTop = "10" horizontalAlign = "center"> <mx: dataGrid id = "dataGrid" width = "100%" height = "90%" dataProvider = "{gridArray}" textAlign = "center"> <mx: columns> <mx: dataGridColumn headerText = "" dataField = "week"/> <mx: DataGridColumn headerText = "apple" dataField = "apple"/> <mx: dataGridColumn headerText = "ratio" dataField = "rate" labelFunction = "formatDataGrid"/> </mx: columns> </mx: DataGrid> </mx: VBox> </s: application>
3. Implementation result
The Operation character formatting for table formatting is different from that for numeric formatting.
It is more suitable to use hand-drawn images. If the picture is wrong, you can erase it again. Select the line type for the rough border. The drop-down menu for the outer box is displayed. Select the line type. What does Gray shading mean? Is it the border color? This is also selected in the drop-down menu, select the color and line type, then select the drawing border, and then frame to add the border range is OK. Very simple.
As for the internal line, do a good job first, and then make the outer frame, which is simple.
In a workbook, how can we find data greater than a certain value in a column and copy them to a new workbook?
We recommend that you use the format = "formatting condition" to set a value greater than this value and distinguish it with special coloring;
Or use the IF formula.