CellList小部件编号不能超过25

时间:2012-05-04 12:37:44

标签: gwt

我已经在CellList上工作了几个星期,我发现它很糟糕。

那些日子我想打印一个包含70多个元素的列表,但是我注意到我的CellList不会超过25:从0到24.为了确保问题与我的项目没有关系,我决定在新的和氏族项目中测试代码,但它有相同的结果。

这是我的代码:

CustomCell bodyCell = new CustomCell();
CellList<String> coreCellList = new CellList<String>(bodyCell);
List<String> list = new ArrayList<String>();
for (int i=0; i<74; i++) {
    list.add("hello_"+i);
}
coreCellList.setRowData(0, list);
coreCellList.setRowCount(list.size(), true);

RootPanel.get().add(coreCellList);

和CustomCell:

public class CustomCell extends AbstractCell<String> {
interface Templates extends SafeHtmlTemplates {

        String style = "cell";

        @SafeHtmlTemplates.Template("<div class=\"" + style
                + "\" style = 'height : 15%'>{0}<br/></div>")
        SafeHtml cell(SafeHtml value);
    }

    private static Templates templates = GWT.create(Templates.class);

    @Override
    public void render(com.google.gwt.cell.client.Cell.Context context,
            String value, SafeHtmlBuilder sb) {
        SafeHtml safeValue = SafeHtmlUtils.fromString(value);

        SafeHtml rendered = templates.cell(safeValue);

        sb.append(rendered);
    }
}

感谢您的帮助。

3 个答案:

答案 0 :(得分:4)

当我不想分页时,我总是使用下面的代码传递我的CellTables和CellLists。

public static void setupOnePageList(final AbstractHasData<?> cellTable) {
    cellTable.addRowCountChangeHandler(new RowCountChangeEvent.Handler() {
        @Override
        public void onRowCountChange(RowCountChangeEvent event) {
            cellTable.setVisibleRange(new Range(0, event.getNewRowCount()));
        }
    });
}

答案 1 :(得分:0)

CellList默认使用分页,页面大小为25.如果向页面添加SimplePager,则可以控制要显示的数据。

我建议不要通过将页面大小设置为数据列表的大小来禁用分页,因为旧版浏览器(尤其是IE8及更早版本)会遇到严重的性能问题,具体取决于演示文稿的复杂性和列表的大小。

要添加寻呼机,请参阅the DevGuide

// Create a SimplePager.
SimplePager pager = new SimplePager();

// Set the cellList as the display.
pager.setDisplay(cellList);

答案 2 :(得分:-1)

在以下情况下:

cellTable.setVisibleRange(new Range(0, event.getNewRowCount()));

不起作用。然后使用setVisibleRangeAndClearData触发forceRangeChangeEvent

cellTable.setVisibleRangeAndClearData(new Range(0, event.getNewRowCount()), true);