[英]Adding links to a row in a column on click (CellTable)
我有一個CellTable,當我單擊添加按鈕時,我想在其中向行添加幾個鏈接。 現在,我面臨的問題是,當我單擊添加按鈕時,鏈接將被添加到該列中的所有行。 某種程度上,我只能將內容添加到列中。
// shows project column
final MultipleLinkTextCell projectCell = new MultipleLinkTextCell();
final Column<Booking, String> projectColumn = new Column<Booking, String>(
projectCell) {
@Override
public String getValue(Booking project) {
return "";
}
};
getView().getTimeTable().addColumn(projectColumn, "Tasks");
帶按鈕的示例
@Override
protected void render(com.google.gwt.cell.client.Cell.Context context,
SafeHtml data, SafeHtmlBuilder sb) {
String string = "";
for (int i = 0; i < value; i++) {
string += "<button type=\"button\" style=\" height:20px; width:22px\">";
}
sb.appendHtmlConstant(string);
if (data != null) {
sb.append(data);
}
}
我正在考慮使用Anchor小部件,因為我可以使用它來處理gwtp中的placemanager。 但是我仍然不知道如何將小部件添加到特定行。
//更新:我現在是這樣做的,它可以工作,但是最好使用揭示管理器。 硬編碼的鏈接有點不好,因為在更改Web服務器時,我總是需要更改對鏈接的引用。 我得到了一個字符串,其中包含多個用逗號分隔的值。
@Override
protected void render(com.google.gwt.cell.client.Cell.Context context,
SafeHtml data, SafeHtmlBuilder sb) {
String stringData = data.asString();
String[] splitResult = stringData.split(",");
for (int i = 0; i < splitResult.length; i++) {
if (!splitResult[i].equals("")) {
sb.appendHtmlConstant("<div><a href=\"http://127.0.0.1:8888/gwtpTimeTracking.html?gwt.codesvr=127.0.0.1:9997#project;projectid="+splitResult[i].substring(0, 7)+"\">"
+ splitResult[i].substring(0, 7) + "</a></div>");
}
}
您不能在CellWidgets
使用任何Widget。
然而,你可以創建一個模仿它的自定義單元格或創建一個ActionCell
並添加VaueUpdater
觸發一個PlaceRequest
事件。
為了將鏈接添加到特定行,您必須向在CellTable
呈現的DTO添加一個字段(即List<String> links
)。 單擊“添加”按鈕時,必須在列表中修改特定DTO的字段。
MyDTO obj = // get the specific DTO from the DataProvider
obj.setLinks(LIST OF LINKS);
在自定義單元格的渲染方法中,您檢查字段(即links
),然后渲染鏈接或不顯示鏈接。
渲染方法中的value
數據從何而來?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.