java SmartGWT - 动态更新 ListGridRecord
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2675038/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SmartGWT - Update ListGridRecord dynamically
提问by Mark Hazlewood
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.
我正在使用 SmartGWT,并且使用 setData() 调用填充了 ListGridRecords 数组的 ListGrid。我正在尝试更新单个记录的进度属性(在用于测试的计时器上)并在浏览器中更新。我尝试了 draw()、redraw()、markForRedraw() 等的各种组合,但都无济于事。
I also tried overriding the updateRecordComponent() method in my table class, but it only gets called when the records are first created (after createRecordComponent()).
我还尝试在我的表类中覆盖 updateRecordComponent() 方法,但只有在第一次创建记录时(在 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.
在此先感谢您的帮助。
回答by Simson
I solved the dynamic update with:
我解决了动态更新:
grid.getRecord(i).setAttribute(name, value);
grid.refreshRow(i);
resp.
分别
grid.refreshCell(i, j);
回答by ciczan
ListGrid has an updateData method, where you can pass a record. Have you tried it?
ListGrid 有一个 updateData 方法,您可以在其中传递一条记录。你试过吗?
回答by dube
a blunt and not very high-performance way is simply setting your records array again with setData or setRecords
一个生硬而不是非常高性能的方法是简单地使用 setData 或 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(...);

