我只想更新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
答案 0 :(得分: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();
}
});
}
}