Flex Hack 02:datagrid end of column for data rollup

Source: Internet
Author: User

Excel's table will have a row of data in the back of a set of data to show the table of the average, the maximum, the minimum value, in flex to do a little action can make a similar effect.

Actually Alex Harui has already made the request for us, we first look at the operation effect:

In fact, the principle is very simple is to rewrite the DataGrid at the end of the column to add a uicomponent is named: Datagridfooter, let it show the average, the maximum, etc., where the most important is to rewrite the DataGridColumn, In this class we add a footercolumn:datagridcolumn so that the Footercolumn Labelfunction calculates the corresponding average, the maximum value, etc. (see here for the use of labelfunction: Flex Hack 01:labelfunction), the code is as follows:

import mx.controls.dataGridClasses.DataGridColumn;
     [DefaultProperty("footerColumn")]
     public class FooterDataGridColumn extends DataGridColumn
     {
          public function FooterDataGridColumn()
          {
           super();
          }
          /**//**
          * 用这个对应的labelFunction计算出这一列的最大值或最小值等等
          * **/
          public var footerColumn:DataGridColumn;
     }

The DataGrid is then rewritten to display the end of the column, such as overriding the Createchildren method:

override protected function createChildren():void
         {
             super.createChildren();
             if (!footer)
             {
                 footer = new DataGridFooter();
                 footer.styleName = this;
                 addChild(footer);
             }
         }

Then rewrite the Adjustlistcontent method to determine the location of the footer:

override protected function adjustListContent(unscaledWidth:Number =  -1,
                                             unscaledHeight:Number = -1):void
         {
           super.adjustListContent(unscaledWidth,  unscaledHeight);
           listContent.setActualSize(listContent.width,  listContent.height - footerHeight);
           footer.setActualSize(listContent.width,  footerHeight);
           footer.move(listContent.x, listContent.y +  listContent.height + 1);
          }

At the same time, when some attributes are changed or dragged to update the position of footer, and so on, then we have to rewrite a method:

override public function invalidateDisplayList():void
          {
               super.invalidateDisplayList();
               if (footer)
                    footer.invalidateDisplayList();
          }

There is also a class datagridfooter, this is our protagonist, used to display the data at the end of the column, there is nothing special about this class, is to calculate their location display, and so on, interested friends can download the code in the following information to see.

http://blogs.adobe.com/aharui/DataGridFooter3/dg.swf

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.