0

我只想更新 CellTable 列。

参见例如。

         Header1 |  Header2 | Header3 |
        -------------------------------
        Column11|  Column12| Column13| 
        Column21|  Column22| Column23| 
        Column31|  Column32| Column33| 

   final TextColumn<Student> nameColumn = new TextColumn<Student>() {

        @Override
        public String getValue(Student object) {
            return object.getName();
        }
    };
    cellTable.addColumn(nameColumn, "Name");

    final TextColumn<MyDTO> classColumn = new TextColumn<MyDTO>() {

        @Override
        public String getValue(Student object) {
            return object.getClassName();
        }
    };
    cellTable.addColumn(classColumn, "Age");

    final TextColumn<Student> subjectColumn = new TextColumn<Student>() {

        @Override
        public String getValue(Student object) {
            return object.getMark();
        }
    };

    cellTable.addColumn(subjectColumn, "Subject");

执行某些操作时,我只想更新 Column22、column23 等......就像 Column32、Column33......

谁能帮我?

提前致谢, Gnik

4

1 回答 1

1

您可以为 CellTable 使用像 ListDataProvider 这样的数据提供程序。数据提供者保存表的数据并与表相关联。因此,当数据提供者中的数据发生任何变化时,当您调用 refresh() 方法时,这些变化将反映在表中。这是完整的代码(我已经修改了一些可用的代码here

public class GWTCellTable implements EntryPoint {
// A simple data type that represents a contact.
private static class Contact {
    private String address;
    private String name;

    public Contact(String name, String address) {
        this.name = name;
        this.address = address;
    }
}

// The list of data to display.
private static List<Contact> CONTACTS = Arrays.asList(new Contact("John", "123 Fourth Road"), new Contact("Mary", "222 Lancer Lane"), new Contact("Zander",
        "94 Road Street"));

public void onModuleLoad() {

    // Create a CellTable.
    CellTable<Contact> table = new CellTable<Contact>();

    // Create name column.
    TextColumn<Contact> nameColumn = new TextColumn<Contact>() {
        @Override
        public String getValue(Contact contact) {
            return contact.name;
        }
    };

    // Create address column.
    TextColumn<Contact> addressColumn = new TextColumn<Contact>() {
        @Override
        public String getValue(Contact contact) {
            return contact.address;
        }
    };

    // Add the columns.
    table.addColumn(nameColumn, "Name");
    table.addColumn(addressColumn, "Address");

    // Create a data provider.
    final ListDataProvider<Contact> dataProvider = new ListDataProvider<Contact>();

    // Connect the table to the data provider.
    dataProvider.addDataDisplay(table);

    // Add the data to the data provider, which automatically pushes it to
    // the
    // widget.
    List<Contact> list = dataProvider.getList();
    for (Contact contact : CONTACTS) {
        list.add(contact);
    }

    // Add it to the root panel.
    RootPanel.get().add(table);

    Button button = new Button("Update table");
    RootPanel.get().add(button);

  //Clicking on the update button, updates the first row of the table
    button.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            dataProvider.getList().get(0).name = "Ganesh";
            dataProvider.getList().get(0).address = "Gachibowli";
            dataProvider.refresh();
        }
    });
}
}
于 2012-05-18T02:18:43.687 回答