0
votes

I am stuck in a problem working on Flex datagrid, in an AIR application.

How can I access a specific row in datagrid in Flex. Please note that i am not talking about the selectedItem or any particular record of dataProvider of datagrid.

What exactly I want to do is I am showing some files data (name, description etc.) on a datagrid, and the data of these files comes from an array which is the dataProvider of the datagrid.

Now when these files are being uploaded one by one to the server (using a webservice), I want to show a ProgressBar on, say, "Progress" column in the datagrid. How can I access this column for a particular row in datagrid i.e. current file being uploaded.

Please refer to image to better understand my query.enter image description here

Please guide me.

Thanks

2

2 Answers

1
votes

Preface, I use the Swiz Framework, so you will just have to adapt what I am saying to Native Flex or another framewok.

I would attack this by having an event that would be fired when you started the upload. This event would have a property that signified which filename is being uploaded.

var e:DataGridEvent = new DataGridEvent(DataGridEvent.START_FILE_UPLOAD);
e.fileName = uploadFileName;
dispatcher.dispatch(e);

Each row in the DataGrid is a new instance of an itemRenderer(there are no other ways to make it have a progressbar or anything fancy). So after setting the itemRenderer to your MXML component, just have it monitor the event being dispatched.

[EventHandler(event="DataGridEvent.START_FILE_UPLOAD", properties="fileName")]
public function startFileUpload(fileName:String):void
{
    if(fileName == dataGride.fileName)
      ........//Show progress bar or whatever

In this manor, all of the rows will respond to the given event, and show the progress bar ONLY if it has the same filename as the file being uploaded. If filename isn't unique(I think it would be), you will have to have some sort of unique ID.

The same general process will be done with the status progress. Just fire a different event being FILE_UPLOAD_STATUS_UPDATE with the percentage and filename. Then handle the event properly.

0
votes

The simplest way to meet your needs is to create custom item renderer with progress bar for progress column and add 3 additional fields to the file data (an element of your data provider):

  1. public var inProgress:Boolean
  2. public var bytesLoaded:int
  3. public var bytesTotal:int

The progress bar in the item renderer can use data binding for switching visibility depending on inProgress flag value. And you can update progress using the same data binding with bytesLoaded and bytesTotal values.

You can read more about custom item renderers in official documentation.