2

我使用 flex table 来显示从 db 获取的数据。当表格包含大量列时,渲染 flextable 需要很长时间(我已经在 80 列和 38 行的表格上对其进行了测试),虽然它没有完全渲染,但我无法对页面做任何事情。所以我使用Schedule.get().scheduleIncremental(ReapitingCommand command)如下:

final int  WORK_CHUNK = 2;    
Scheduler.get().scheduleIncremental(new RepeatingCommand() {
            int rowCounter = 0;

            @Override
            public boolean execute() {
            for (int i = rowCounter; i < rowCount; i++, rowCounter++) {
                for (int j = 0; j < columnCount; j++) {
                table.setText(i, j, data.get(i)[j]);
                }
                if (rowCounter % WORK_CHUNK == 0)
                return true;
            }
            return false;
            }
        });

但是如果我在对象中有 9 行和 3 列,data它只会呈现 2 行。我怎样才能提高它的性能,因为正如我之前所说,如果有 38 行和 80 列,那么在没有scheduleIncremental. 甚至浏览器也会弹出脚本可能已停止响应的窗口。

4

2 回答 2

2

为什么不使用CellTable而不是 FlexTable 来呈现数据?
与 FlexTable 相比,CellTable 在渲染大量数据方面应该更加高效。

于 2011-12-10T16:59:14.740 回答
2

对于上面的代码,我会这样做。摆脱第一个 for 循环,因为 execute() 是递归的。

Scheduler.get().scheduleIncremental(new RepeatingCommand() {
    int rowCounter = 0;
    int rowCount = 10;

@Override
public boolean execute() {

// do some work
    for (int j = 0; j < columnCount; j++) {
    table.setText(i, j, data.get(i)[j]);
}

rowCounter++;

if (rowCounter >= rowCount)
    return false;

return true;
   }
});
于 2013-06-05T18:14:45.737 回答