有沒有什麼辦法可以將clickHandlers(或任何類型的處理程序)添加到CellTable中列的標題?我想爲我的CellTable添加一些排序功能,我沒有看到Column或Header類中的任何方法可以實現這一點。我用this發佈瞭解如何使用CellTable。GWT 2.1 CellTable列標題點擊事件
8
A
回答
3
CellTable上還沒有支持Sort的方式。然而,有一個手動解決方法涉及到很多代碼苦差事。根據費用樣本,請參閱自行車棚中的SortableHeader
和SortableColumn
。您將在com.google.gwt.sample.expenses.gwt.client.ExpenseDetails
中找到用法。你可以使用它,直到下一個版本的具體內容出現。
退房目錄:http://google-web-toolkit.googlecode.com/svn/trunk/bikeshed
0
使用GWT 2.1的最終版本,還沒有被添加到CellTable對排序的列任何支持?或者,在看過自行車的例子之後,它仍然是自己的解決方案嗎?
8
解決方法click事件:
Header<String> columnHeader = new Header<String>(new ClickableTextCell()) {
@Override
public String getValue() {
return columnName;
}
};
columnHeader.setUpdater(new ValueUpdater<String>() {
@Override
public void update(String value) {
Window.alert("Header clicked!");
}
});
table.addColumn(column, columnHeader);
0
CellTable<Contact> table = new CellTable<Contact>();
// Create name column.
final TextColumn<Contact> nameColumn = new TextColumn<Contact>() {
@Override
public String getValue(Contact contact) {
return contact.name;
}
};
// Create a data provider.
ListDataProvider<Contact> dataProvider = new ListDataProvider<Contact>();
// Connect the table to the data provider.
dataProvider.addDataDisplay(table);
final List<Contact> list = dataProvider.getList();
for (Contact contact : CONTACTS) {
list.add(contact);
}
final ListHandler<Contact> columnSortHandler = new ListHandler<Contact>(
list);
Header<String> columnHeader = new Header<String>(new ClickableTextCell()) {
@Override
public String getValue() {
return "Name";
}
};
columnHeader.setUpdater(new ValueUpdater<String>() {
@Override
public void update(String value) {
if (Window.confirm("Want to do?")){
nameColumn.setSortable(true);
columnSortHandler.setComparator(nameColumn,
new Comparator<Contact>() {
public int compare(Contact o1, Contact o2) {
if (o1 == o2) {
return 0;
}
// Compare the name columns.
if (o1 != null) {
return (o2 != null) ? o1.name.compareTo(o2.name) : 1;
}
return -1;
}
});
} else nameColumn.setSortable(false);
}
});
// Make the name column sortable.
nameColumn.setSortable(false);
// Create address column.
TextColumn<Contact> addressColumn = new TextColumn<Contact>() {
@Override
public String getValue(Contact contact) {
return contact.address;
}
};
// Add the columns.
table.addColumn(nameColumn, columnHeader);
table.addColumn(addressColumn, "Address");
// Add the data to the data provider, which automatically pushes it to the
// widget.
// Add a ColumnSortEvent.ListHandler to connect sorting to the
// java.util.List.
//------------------ Code to add --------------------------------//
VerticalPanel vp = new VerticalPanel();
table.addColumnSortHandler(columnSortHandler);
//------------------ Code end --------------------------------//
// We know that the data is sorted alphabetically by default.
table.getColumnSortList().push(nameColumn);
// Add it to the root panel.
vp.add(table);
RootPanel.get().add(vp);
相關問題
- 1. GWT CellTable,點擊時禁用ButtonCell
- 2. 將鼠標懸停在GWT celltable的列上的事件
- 3. jqGrid列標題點擊事件
- 4. GWT 2.1 CellTable僅顯示加載條
- 5. HubSection標題點擊事件?
- 6. GWT 2.4 CellTable問題
- 7. GWT CellTable OnClick問題
- 8. html body gwt點擊事件
- 9. 消費GWT點擊事件
- 10. GWT CellTable具有凍結標題和初始列
- 11. GWt 2.2.0凍結CellTable中的標題行
- 12. GWT CellTable標題中的TextCell和TextInputCell
- 13. CellTable點擊吞嚥
- 14. Fullcalender上點擊標題的點擊事件標題警報ID
- 15. 帶有複選框選擇和行單擊事件的GWT CellTable
- 16. GWT 2.5 - CellTable行Onclick(單擊)事件 - 不包含行索引
- 17. 在CellTable單元格中添加雙擊事件 - GWT
- 18. GWT帶標籤和圖像的Celltable列
- 19. 作爲列的GWT CellTable標頭
- 20. GWT - celltable
- 21. GWT - celltable
- 22. GWT 2.5.1 CellTable和SimplePager問題
- 23. GWT樣式CellTable標頭
- 24. 如何隱藏GWT CellTable中的列標題?
- 25. 如何將圖像插入CellTable(GWT)的列標題中?
- 26. 合併列標題在DataGrid中或cellTable在GWT 2.4
- 27. 如何使GWT celltable單元不接受點擊或焦點
- 28. GWT - 如何分類celltable列?
- 29. GWT CellTable - 設置列寬
- 30. 圖表標題圖表點擊事件
好像鏈接不再有效。試試這一個http://code.google.com/p/google-web-toolkit/source/browse/branches/2.1/bikeshed/src/com/google/gwt/sample/expenses/gwt/client/ – stuff22 2010-11-19 17:45:56
@ stuff22編輯答案。 – 2013-05-28 21:01:29