My guess is that the OP will have the records inside a single string and so 
will need to iterate through the string picking out the individual fields from 
the spaces between them.

Paul
  ----- Original Message ----- 
  From: Giles Roadnight 
  To: flexcoders@yahoogroups.com 
  Sent: Thursday, September 20, 2007 2:48 PM
  Subject: Re: [flexcoders] Re: Parsing a flat file in flex?


  Something liek this:

  var records:Array // I'm assuming an array or arrays from your post
  var dataProvider:ArrayCollection = new ArrayCollection();

  for (var i:int = 0; i < records.length; i++)
  {
       var currentObject:Object = new Object();
       for (var j:int = 0; j < records[i].length; i++)
       {
            currentObject["col" + j] = records[i][j];
       }
       dataProvider.addItem(currentObject); 
  }

  then the grid:

  <mx:DataGrid id="dg" width="100%"
  height="100%" rowCount="5" dataProvider="{dataProvider}" >
  <mx:columns>
  <mx:DataGridColumn dataField="col0"
  headerText="Date" textAlign="center" />
  <mx:DataGridColumn dataField="col1"
  headerText="Date" textAlign="center" />

  ect, I hope that helps


  On 9/20/07, djdyland < [EMAIL PROTECTED]> wrote:
    I understand what your saying.. but I'm not sure how to do that in 
    actionscript? anyway you can just show me how you would do this part

    turn each line into an object with properites (e.g. col1, col2 or
    whatever you like

    Thanks in advance

    --- In flexcoders@yahoogroups.com, "Giles Roadnight" <[EMAIL PROTECTED]> 
    wrote:
    >
    > If you turn each line into an object with properites (e.g. col1, 
    col2 or
    > whatever you like, somethign more descriptive perhaps) put all 
    these objects
    > into an ArrayCollection and use this ArrayCollection as the 
    dataprovider for
    > your grid.
    > 
    > In the datagrid use the property names of the object as the 
    datafield for
    > each column.
    > 


    > On 9/20/07, djdyland <[EMAIL PROTECTED]> wrote:
    > >
    > > Hey Gordon,
    > >
    > > Thanks for the reply. I got it to work using split like you said.
    > > I'm now stuck trying to put the data in a datagrid. The data is 
    now
    > > in an array but I'm not sure how you reference each element for a
    > > column in the data provider or the data grid.
    > >
    > > The data looks something like this
    > > (Record 1)
    > > 09/17/07 < element 0
    > > 245 < element 1
    > > 37 < etc
    > > 36
    > > 44
    > > 194
    > > 100
    > > 2
    > > 45
    > > 4
    > > 462
    > > 63906
    > >
    > > (record 2)
    > > 09/18/07
    > > 263
    > > 41
    > > 34
    > > 43
    > > 197
    > > 95
    > > 1
    > > 45
    > > 3
    > > 459
    > > 63906
    > >
    > > And my datagrid would be
    > >
    > > <mx:DataGrid id="dg" width="100%"
    > > height="100%" rowCount="5" dataProvider="{array}" >
    > > <mx:columns>
    > > <mx:DataGridColumn
    > > headerText="Date" textAlign="center" />
    > > <mx:DataGridColumn
    > > headerText="CoreTechInit" textAlign="center"/>
    > > <mx:DataGridColumn
    > > headerText="ServerInit" textAlign="center"/>
    > > <mx:DataGridColumn
    > > headerText="ImportPackets" textAlign="center"/>
    > > <mx:DataGridColumn
    > > headerText="Merge" textAlign="center"/>
    > > <mx:DataGridColumn
    > > headerText="Layout" textAlign="center"/>
    > > <mx:DataGridColumn
    > > headerText="Render" textAlign="center"/>
    > > <mx:DataGridColumn
    > > headerText="CalcTime" textAlign="center"/>
    > > <mx:DataGridColumn
    > > headerText="RenderOverhead" textAlign="center"/>
    > > <mx:DataGridColumn
    > > headerText="AppOverhead" textAlign="center"/>
    > > <mx:DataGridColumn
    > > headerText="Total" textAlign="center"/>
    > > <mx:DataGridColumn
    > > headerText="FileSize" textAlign="center"/>
    > > </mx:columns>
    > > </mx:DataGrid>
    > >
    > > So my question now is How do I associate each array element with 
    its
    > > proper place holder in the datagrid?? Do I have to create and
    > > associative array or something? I'm assuming it has something to 
    do
    > > with the datafield of each column?
    > >
    > > Any help is greaty appreciated
    > > Thanks
    > > Dylan
    > >

    > > --- In flexcoders@yahoogroups.com <flexcoders%
    40yahoogroups.com>, "Gordon
    > > Smith" <gosmith@>
    > >
    > > wrote:
    > > >
    > > > Is this a file on the server whose contents you're getting as 
    a big
    > > > String? If so, you could probably just use the split() method 
    of
    > > String
    > > > to first split on carriage-return or newline, and then split 
    each
    > > line
    > > > on whitespace.
    > > >
    > > > - Gordon
    > > >
    > > > ________________________________
    > > >
    > > > From: flexcoders@yahoogroups.com <flexcoders%40yahoogroups.com>
    > > [mailto:flexcoders@yahoogroups.com <flexcoders%
    40yahoogroups.com>] On
    > > > Behalf Of djdyland
    > > > Sent: Wednesday, September 19, 2007 10:36 AM
    > > > To: flexcoders@yahoogroups.com <flexcoders%40yahoogroups.com>
    > > > Subject: [flexcoders] Parsing a flat file in flex?
    > > >
    > > >
    > > >
    > > > Can anyone point me in the direction of how this might be done?
    > > > I want to parse or convert a flat file separated by spaces into
    > > xml or
    > > > some sort of structure I can then use a dataprovider inside 
    flex..
    > > The
    > > > file looks something like this
    > > >
    > > > Date CoreTechInit ServerInit ImportPackets Merge
    > > > 12/16/04 0 3 43 47
    > > > 12/17/04 0 9 43 49
    > > > 12/18/04 0 9 40 53
    > > > 12/19/04 0 6 40 46
    > > > 12/20/04 0 6 40 47
    > > > 01/03/05 0 3 46 56
    > > > 01/04/05 0 6 46 46
    > > >
    > > > Thanks
    > > > Dylan
    > > >
    > >
    > > 
    > >
    > 
    > 
    > 
    > -- 
    > Giles Roadnight
    > http://giles.roadnight.name
    >






  -- 
  Giles Roadnight
  http://giles.roadnight.name  

Reply via email to