SmartGWT - 动态更新ListGridRecord

时间:2010-04-20 12:29:46

标签: java gwt smartgwt

我正在使用SmartGWT,我使用setData()调用填充了ListGridRecords数组的ListGrid。我正在尝试更新单个记录的进度属性(在计时器上进行测试)并在浏览器中更新。我尝试过draw(),redraw(),markForRedraw()等各种组合无济于事。

我也尝试覆盖表类中的updateRecordComponent()方法,但只在首次创建记录时调用它(在createRecordComponent()之后)。

我应该注意,我不想通过绑定到DataSource来实现这一点。我只是希望能够在客户端更新属性。

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;
   }

提前感谢您的帮助。

3 个答案:

答案 0 :(得分:1)

我用以下方法解决了动态更新:

grid.getRecord(i).setAttribute(name, value);
grid.refreshRow(i);

RESP。

grid.refreshCell(i, j);

答案 1 :(得分:0)

ListGrid有一个updateData方法,您可以在其中传递记录。你试过吗?

答案 2 :(得分:0)

一种生硬而不是很高效的方法就是用setData或setRecords再次设置你的记录数组

grid.setData(recordArr);

我在我的应用中使用它,但仅仅因为所有记录都已更新。

BTW:你可以设置一个客户端数据源

dataSource.setClientOnly(true);
dataSource.setTestData(...);