5

At first I used the Grid. After creating a new version of the GWT, I want to replace the Grid on the CellTable.

2
  • I don't understand exactly what you are asking. Can you provide some code examples or expand your description?
    – jzd
    Dec 3, 2010 at 13:26
  • I can't find a method to remove row in CellTable class like "removeRow(int rowNum)" in Grid
    – angry
    Dec 3, 2010 at 14:00

3 Answers 3

10

Check out the javadoc for details. My example is like the one you'll find there (just a little extended):

public void onModuleLoad() {
    final CellTable<Row> table = new CellTable<Row>();

    TextColumn<Row> firstColumn = new TextColumn<Starter.Row>() {

        @Override
        public String getValue(Row object) {
            return object.firstColumn;
        }
    };
    table.addColumn(firstColumn, "header one");

    TextColumn<Row> secondColumn = new TextColumn<Starter.Row>() {

        @Override
        public String getValue(Row object) {
            return object.secondColumn;
        }
    };
    table.addColumn(secondColumn, "header two");

    TextColumn<Row> thirdColumn = new TextColumn<Starter.Row>() {

        @Override
        public String getValue(Row object) {
            return object.thirdColumn;
        }
    };
    table.addColumn(thirdColumn, "header three");

    table.setRowCount(getList().size());
    final ListDataProvider<Row> dataProvider = new ListDataProvider<Starter.Row>(getList());
    dataProvider.addDataDisplay(table);

    final SingleSelectionModel<Row> selectionModel = new SingleSelectionModel<Starter.Row>();
    table.setSelectionModel(selectionModel);

    Button btn = new Button("delete entry");
    btn.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            Row selected = selectionModel.getSelectedObject();
            if (selected != null) {
                dataProvider.getList().remove(selected);
            }
        }
    });

    RootPanel.get().add(table);
    RootPanel.get().add(btn);

}

private class Row {

    private String firstColumn;
    private String secondColumn;
    private String thirdColumn;

    public Row(String firstColumn, String secondColumn, String thirdColumn) {
        this.firstColumn = firstColumn;
        this.secondColumn = secondColumn;
        this.thirdColumn = thirdColumn;
    }

}

private LinkedList<Row> getList() {
    LinkedList<Row> list = new LinkedList<Row>();
    list.add(new Row("first", "entry", "foo"));
    list.add(new Row("second", "entry", "foo"));
    list.add(new Row("third", "entry", "foo"));
    list.add(new Row("fourth", "entry", "foo"));
    return list;
}
2

Or you can just run the cycle like that

@UiHandler("combo") 
public void onChange(ChangeEvent e) {
    textBoxes.clear();
    searchFields.clear();
    while(resultsTable.getColumnCount()!=0) {
        resultsTable.removeColumn(0);
    }
    resultsTable.redraw();

Where resultsTable is a CellTable

1

CellTable as part of new DataPresentationWidgets used just to display data. So you should delete according member from list of data which CellTable using to display.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.