Colspan and Rowspan in CellTable

2019-08-12 15:17发布

问题:

I'm implementing a table which has both colspan and rowspan cells. I used FlexTable before but decided to use CellTable. But it looks like CellTable does not support adding style while FlexTable did... Please look at the picture to know what I'm trying to do:

Any suggestions are welcome.

回答1:

You can use an AbstractCellTableBuilder to render your own strucuture.
Have a look at the Custom DataGrid showcase.



回答2:

;
    FlexTable table = new FlexTable();
    FlexTable.FlexCellFormatter flexCellFormatter =table.getFlexCellFormatter();
    flexCellFormatter.setColSpan(3,0,2);
    final TextBox textBox = new TextBox();
    Label label = new Label();
    label.setText("Name");
    table.setWidget(0, 0, label);
    table.setWidget(0, 1, textBox);
    final TextBox textBox1 = new TextBox();
    Label label1 = new Label();
    label1.setText("Surname");
    table.setWidget(1,0,label1);
    table.setWidget(1, 1, textBox1);
    final TextBox textBox2 = new TextBox();
    Label label2 = new Label();
    label2.setText("e-mail");
    table.setWidget(2,0, label2);
    table.setWidget(2, 1, textBox2);

    Button button = new Button("apply", new ClickHandler() {
        @Override``
        public void onClick(ClickEvent event) {
            String name = textBox.getText();
            String surname = textBox1.getText();
            Window.alert("Your name is " + name + "Your surname is " + surname);
        }
    });
    table.setWidget(3, 0, button);//Write this code, then run, you can answer! goodLuck :-))


标签: gwt celltable