java 如何从单元格表中删除一行

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4345890/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 05:59:52  来源:igfitidea点击:

How to remove a row from the Cell Table

javagwt

提问by angry

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

起初我使用网格。创建新版本的 GWT 后,我想替换 CellTable 上的 Grid。

回答by z00bs

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

有关详细信息,请查看javadoc。我的例子就像你会在那里找到的那​​个(只是有点扩展):

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;
}

回答by Denys

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

其中 resultsTable 是一个 CellTable

回答by Ilia Akhmadullin

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

CellTable 作为新DataPresentationWidgets 的一部分,仅用于显示数据。所以你应该从 CellTable 用来显示的数据列表中删除相应的成员。