Creating an auto-scrolling DataGrid control in Flex using as3


This is action script version of  http://blog.flexexamples.com/2009/01/31/creating-an-auto-scrolling-datagrid-control-in-flex/  post

1:  <?xml version="1.0" encoding="utf-8"?>
2:  <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
3:                xmlns:s="library://ns.adobe.com/flex/spark"
4:                xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" creationComplete="application1_creationCompleteHandler(event)">
5:      <fx:Script>
6:          <![CDATA[
7:              import mx.collections.ArrayCollection;
8:              import mx.controls.DataGrid;
9:              import mx.controls.dataGridClasses.DataGridColumn;
10:              import mx.events.CollectionEvent;
11:              import mx.events.FlexEvent;
12:
13:              private var timer:Timer;
14:              private var arr:ArrayCollection;
15:              private var dg:DataGrid;
16:              protected function application1_creationCompleteHandler(event:FlexEvent):void
17:              {
18:                  // TODO Auto-generated method stub
19:                  timer = new Timer(1000);
20:                  arr = new ArrayCollection();
21:                  dg = new DataGrid();
22:                  var columns:Array = new Array();
23:
24:                  var dgIdColumn:DataGridColumn = new DataGridColumn();
25:                  dgIdColumn.dataField="id";
26:                  dgIdColumn.headerText = "ID";
27:                  columns.push(dgIdColumn);
28:
29:                  var dgTimeColumn:DataGridColumn = new DataGridColumn();
30:                  dgTimeColumn.dataField="time";
31:                  dgTimeColumn.headerText = "Timer";
32:                  columns.push(dgTimeColumn);
33:
34:                  dg.columns = columns;
35:                  dg.x = 0;
36:                  dg.y = 0;
37:                  dg.dataProvider = arr;
38:                  addElement(dg);
39:
40:                  timer.addEventListener(TimerEvent.TIMER,onTimerTick);
41:                  arr.addEventListener(CollectionEvent.COLLECTION_CHANGE,onCollectionChange);
42:                  timer.start();
43:              }
44:
45:              private function onTimerTick(e:TimerEvent):void
46:              {
47:                  arr.addItem({id:timer.currentCount,time:"TEMP"});
48:              }
49:
50:              private function onCollectionChange(e:CollectionEvent):void
51:              {
52:                  callLater(scrollDataGrid);
53:              }
54:
55:              private function scrollDataGrid():void
56:              {
57:                  dg.verticalScrollPosition = dg.maxVerticalScrollPosition;
58:              }
59:
60:          ]]>
61:      </fx:Script>
62:      <fx:Declarations>
63:          <!-- Place non-visual elements (e.g., services, value objects) here -->
64:      </fx:Declarations>
65:  </s:Application>
66:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s