开发者

GWT CellTable and SimplePager issue

I am using a CellTable<Contact> in my GWT 2.4 project. Everything worked perfectly, so I decided to add paging to the table by using a SimplePager. The CellTable now displays the correct number of entries (page size), but all the pager buttons are disabled.

I am doing the following:

...
@UiField(provided=true) CellTable<Contact> contactsTable = new CellTable<Contact>();
@UiField SimplePager pager;

private TextColumn<Contact> nameColumn;
private TextColumn<Contact> surnameColumn;

public ViewContactsViewImplDesktop() {
    initWidget(uiBinder.createAndBindUi(this));
    initTable();
}

@Override
public final void updateContactList(final ArrayList<Contact> contacts) {
    contactsTable.setRowCount(contacts.size());

    final ListDataProvider<Contact> dataProvider = new ListDataProvider<Contact>();

    List<Contact> list = dataProvider.getList();

        for (final Contact c : contacts) {
            list.add(c);
        }

        dataProvider.addDataDisplay(contactsTable);

        pager = new SimplePager();
        pager.setDisplay(contactsTable);
        pager.setPageSize(3);

        ListHandler<Contact> nameColumnSorter = new ListHandler<Contact>(list);
        ListHandler<Contact> surnameColumnSorter = new ListHandler<Contact>(list);

        nameColumnSorter.setComparator(nameColumn, new Comparator<Contact>() {
            @Override
            public int compare(Contact c1, Contact c2) {
                return c1.getName().compareTo(c2.getName());
            }
        });

        surnameColumnSorter.setComparator(surnameColumn, new Comparator<Contact>() {
            @Override
            public int compare(Contact c1, Contact c2) {
                return c1.getSurname().compareTo(c2.getSurname());
            }
        });

        contactsTable.addColumnSortHandler(name开发者_运维问答ColumnSorter);
        contactsTable.addColumnSortHandler(surnameColumnSorter);
        contactsTable.getColumnSortList().push(nameColumn);
    }

    private void initTable() {
        nameColumn = new TextColumn<Contact>() {
            @Override
                public String getValue(Contact contact) {
                    return contact.getName();
                }
            };

            surnameColumn = new TextColumn<Contact>() {
                @Override
                public String getValue(Contact contact) {
                    return contact.getSurname();
                }
            };

            nameColumn.setSortable(true);
            surnameColumn.setSortable(true);

            contactsTable.addColumn(nameColumn, "Name");
            contactsTable.addColumn(surnameColumn, "Surname");
    }

Thanks!


Not setting the page size and/or not setting the table's row count manually could do the trick, as hinted in my comment.
I'd love to provide a concise code sample but do not have access to any code using cell widgets right now.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜