2
下一個接收焦點我使用GWT 2.1.0指定哪些細胞應在一CellTable
我有一個CellTable填充的是使用不同的細胞來編輯不同類型的值(例如,日期,串等等)列。我希望用戶能夠在單元格中單擊,鍵入一個值,然後按Enter鍵直接編輯下一個單元格,或者直接單擊選項卡編輯下一個單元格。
我一直在尋找Cell和CellTable接口,但找不到任何看起來相關的東西。我怎樣才能達到這個效果?
下一個接收焦點我使用GWT 2.1.0指定哪些細胞應在一CellTable
我有一個CellTable填充的是使用不同的細胞來編輯不同類型的值(例如,日期,串等等)列。我希望用戶能夠在單元格中單擊,鍵入一個值,然後按Enter鍵直接編輯下一個單元格,或者直接單擊選項卡編輯下一個單元格。
我一直在尋找Cell和CellTable接口,但找不到任何看起來相關的東西。我怎樣才能達到這個效果?
我有類似的要求,我找不到一個開箱即用的解決方案。我結束了繼承TextInputCell並自己添加tabIndex支持。
這裏有一些小部分的子類(希望它會編譯,懶得檢查)。不幸的是,我不能發佈整個子類,因爲它有很多可能與當前問題無關的其他事情。該解決方案負責切換到下一個單元格,但對於輸入支持,您可能需要重寫onBrowserEvent。
public class EditTextInputCell extends TextInputCell
{
int startTabIndex;
interface TabbedTemplate extends SafeHtmlTemplates
{
@Template("<input type=\"text\" value=\"{0}\" tabindex=\"{1}\" class=\"{2}\" title=\"{3}\"></input>")
SafeHtml input(String value, String tabindex, String styleClass, String title);
}
private static TabbedTemplate template;
public EditTextInputCell(int startTabIndex)
{
this.startTabIndex = startTabIndex;
}
@Override
public boolean isEditing(Context context, Element parent, String value)
{
return true;
}
@Override
public void render(Context context, String value, SafeHtmlBuilder sb)
{
// Get the view data.
Object key = context.getKey();
ValidationData viewData = getViewData(key);
if (viewData != null && value.equals(viewData.getCurrentValue()))
{
clearViewData(key);
viewData = null;
}
String strToDisp = (viewData != null && viewData.getCurrentValue() != null) ? viewData.getCurrentValue() : value;
String tabIndex = "" + startTabIndex + context.getIndex() + context.getColumn();
boolean invalid = (viewData == null) ? false : viewData.isInvalid();
String styleClass = "cellTableCell-valid";
String errorMessage = "";
if (invalid)
{
styleClass = "cellTableCell-invalid";
errorMessage = viewData.getMessage();
}
if (strToDisp != null)
{
SafeHtml html = SimpleSafeHtmlRenderer.getInstance().render(strToDisp);
// Note: template will not treat SafeHtml specially
sb.append(getTemplate().input(html.asString(), tabIndex, styleClass, errorMessage));
}
else
{
sb.appendHtmlConstant("<input type=\"text\" tabindex=\"" + tabIndex + "\" class=\"" + styleClass + "\" title=\"" + errorMessage + "\"></input>");
}
}
private TabbedTemplate getTemplate()
{
if (template == null)
{
template = GWT.create(TabbedTemplate.class);
}
return template;
}}