Clint,
I usually create array of
columns and just assign columns property of DataGrid rather then using addColumn API as addColumn as it takes the same
time to set up 10 columns as 1. I would also try to either not have or hide
initial columns as if the data comes faster then presentation it can confuse
user by showing "part" of the grid.
HTH,
ANatole
----- Original Message -----
Sent: Sunday, December 18, 2005 12:36
AM
Subject: Re: [flexcoders] Data Grid
headers
so... i'm having problems
pressing my "L" key
the file names are:
"MultiGrid.mxml" and
"MultiGrid.as"
not
"MutiGrid.mxml" and "MutiGrid.as"
On 12/17/05, Clint
Modien <[EMAIL PROTECTED]>
wrote:
Did
this the other day... here's some code... with a warning though. The
performance is horrible on my 1.7 GHz Pentium M laptop running the 7.x debug
player. It takes about 6 seconds to load what I would call a "very" small
subset of data (45KB). Maybe someone from MM can have a look at it and
see if it can be optimized. Most of what I did was inspired by the grid that
Steven Webster had on his blog here:
http://www.richinternetapps.com/archives/000101.html
I'm
in the process of converting it to a Flex 2.0 app. *i hope it runs
faster there* I'll post that too once I'm finished.
Here's the
example...
---------------- App.mxml
-------------------
<?xml version="1.0"
encoding="utf-8"?> <mx:Application xmlns:mx="
http://www.macromedia.com/2003/mxml"
creationComplete="this_creationComplete()"
themeColor="haloBlue" backgroundColor="#707070"
xmlns="*" > <mx:Panel title="Panel1"
label="Panel1" height="100%" width="100%" >
<mx:Button
id="loadTestDataButton" label="Load" click="loadTestDataButton_click()"
/> <MultiGrid
height="100%" width="100%" dataProvider="{ ModelLocator.rootObj}"
/> </mx:Panel>
<mx:HTTPService id="testService" showBusyCursor="true" useProxy="false"
url="" resultFormat="object"
result="ModelLocator.rootObj
= event.result.root;" />
<mx:Script source="App.as "
/> </mx:Application>
---------------- MutiGrid.mxml
-------------------
<?xml version="1.0"
encoding="utf-8"?> <mx:HDividedBox xmlns:mx="
http://www.macromedia.com/2003/mxml" marginTop="0"
marginBottom="0"> <mx:VBox height="100%"
width="33%" marginTop="20">
<mx:DataGrid id="leftGrid" dataProvider="{ModelLocator.data}"
height="100%" width="100%"
selectedIndex="{lowerGrid.selectedIndex}" hScrollPolicy="on"
vScrollPolicy="off"
vPosition="{lowerGrid.vPosition}">
<mx:columns>
<mx:Array>
<mx:DataGridColumn headerText="Name" columnName="name"
/>
<mx:DataGridColumn headerText="Group" columnName="group" />
</mx:Array>
</mx:columns>
</mx:DataGrid>
</mx:VBox> <mx:Canvas height="100%"
width="66%" verticalGap="-1">
<mx:DataGrid
id="upperGrid" hPosition="{lowerGrid.hPosition}" textAlign="center"
hScrollPolicy="on" height="40" width="100%" vScrollPolicy="on"
/> <mx:DataGrid
id="lowerGrid" dataProvider="{ModelLocator.data}" height="100%"
width="100%"
vScrollPolicy="on" hScrollPolicy="on" y="19" selectedIndex="{
leftGrid.selectedIndex}" />
</mx:Canvas> <mx:Script
source="MultiGrid.as"/> </mx:HDividedBox>
----------------
MutiGrid.as -------------------
import
mx.controls.gridclasses.DataGridColumn;
public
function set dataProvider(val:Object)
{ //make sure we're getting
array's var data
= mx.utils.ArrayUtil.toArray(val.GridDataSet.GridData
); var columns =
mx.utils.ArrayUtil.toArray(val.Columns.Column);
//format the grids first
renderColumns(columns);
//then bind the child props to the
ModelLocator ModelLocator.data =
""> }
private function renderColumns(columns:Array)
{
upperGrid.removeAllColumns();
lowerGrid.removeAllColumns(); var
columnNumber = 0; for (var i = 0; i
< columns.length; i++)
{ // add columns
to the uppergrid
var columnWidth = 100;
var column = columns[i];
var subColumns:Array =
mx.utils.ArrayUtil.toArray (column.SubColumn);
var dc = new
DataGridColumn();
dc.headerText = column.ColumnName;
dc.width = subColumns.length *
columnWidth;
dc.colNum = i;
upperGrid.addColumn(dc);
// add columns to the lower
grid for (var j
= 0; j < subColumns.length; j++)
{
var subColumn =
subColumns[j];
if(subColumn == undefined) subColumn =
"";
var dc2 = new DataGridColumn();
dc2.colNum =
columnNumber;
columnNumber++;
dc2.headerText =
subColumn;
// dc.setStyle("textAlign",
"center");
dc2.columnName =
"Column_"+column.ColumnID+"_"+subColumn;
dc2.width =
columnWidth;
lowerGrid.addColumn(dc2);
}
} }
---------------- ModelLocator.as
-------------------
class ModelLocator {
public static var
rootObj; public static var data:Array;
--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com
SPONSORED LINKS
YAHOO! GROUPS LINKS
|
- Re: [flexcoders] Data Grid headers Anatole Tartakovsky
-