tags:

views:

707

answers:

2

I am using SmartGWT and I have a ListGrid populated with an array of ListGridRecords using the setData() call. I am trying to update a progress property of a single record (on a timer for testing) and have it update in the browser. I have tried various combinations of draw(), redraw(), markForRedraw() etc. to no avail.

I also tried overriding the updateRecordComponent() method in my table class, but it only gets called when the records are first created (after createRecordComponent()).

I should note that I do NOT want to accomplish this by binding to a DataSource. I just want to be able to update the attribute on the client-side.

ArrayList<SegmentSortRecord> mRecords;
mRecords.add(new SegmentSortRecord("03312010_M001_S004"));
mRecords.add(new SegmentSortRecord("03312010_M001_S005"));
mRecords.add(new SegmentSortRecord("03312010_M001_S006"));
mRecords.add(new SegmentSortRecord("03312010_M001_S007"));

SegmentSortRecord[] records = new SegmentSortRecord[mRecords.size()];
mRecords.toArray(records);

mSortProgressTable.setData(records);

. . .

mTestTimer = new Timer()
{
   public void run()
   {
      mTestPercent += 5;

      if (mTestPercent <= 100)
      {
         mSortProgressTable.getRecord(2).setAttribute(Constants.PROGRESS_COL_NAME, mTestPercent);
         //mSortProgressTable.markForRedraw();
         //mSortProgressTable.redraw();
      }
      else
      {
         mTestPercent = 0;
      }
   }
};

...

@Override
protected Canvas createRecordComponent(final ListGridRecord aRecord, Integer aColumn)
{
   String fieldName = getFieldName(aColumn);      

   // Want to override the behavior for rendering the "progress" field
   if (fieldName.equals(Constants.PROGRESS_COL_NAME))
   {  
      Progressbar bar = new Progressbar();
      bar.setBreadth(10);
      bar.setLength(100);

      // The JavaScript record object contains attributes that we can
      // access via 'getAttribute' functions.
      bar.setPercentDone(aRecord.getAttributeAsInt(Constants.PROGRESS_COL_NAME));

      return bar;
   }

Thanks in advance for any help.

A: 

ListGrid has an updateData method, where you can pass a record. Have you tried it?

ciczan
A: 

a blunt and not very high-performance way is simply setting your records array again with setData or setRecords

grid.setData(recordArr);

I use that in my app, but only because all records are updated anyway.

BTW: you could set up a clientside datasource

dataSource.setClientOnly(true);
dataSource.setTestData(...);
dube
Actually I was trying this method first. My problem was not having direct access to the Progressbar object contained in my record.
Haylwood