2011-03-21 64 views

回答

0

嘗試使用ClickableTextCell並設置其ValueUpdater調用任何你需要的錨做

+0

你有一個簡單的例子添加列可點擊TextCell ????? – 2011-03-21 18:44:19

+0

問題解決http://stackoverflow.com/questions/5384882/so​​lved-how-to-add-clickabletextcell-to-celltable – 2011-03-22 10:01:53

0

創建Column重寫onBrowserEvent方法。

像這樣:

new Column<T, String>(new TextCell()) { 
    @Override 
    public String getValue(T object) { 
     return object.getProperty(); 
    } 

    @Override 
    public void onBrowserEvent(Context context, Element elem, T object, NativeEvent event) { 
     // TODO You can check which event you want to catch 
     Window.open("http://www.stackoverflow.com", "StackOverFlow", ""); 
    } 
}; 
0

這個問題是很老,但仍然將是可以幫助別人的答案。在下面的代碼我使用clickableTextCell和一些造型變化給錨的感覺;)

Column<YourDataClass, String> columnValue = new Column<YourDataClass, String>(
    new ClickableTextCell()) { 

    @Override 
    public String getCellStyleNames(Cell.Context context, YourDataClass object) { 
    return style.clickableText(); 
    } 


    @Override 
    public String getValue(YourDataClass object) {  

    return "Anchor Name"; //This is anchor text eg: Download Something 
    } 
}; 

columnValue.setFieldUpdater(new FieldUpdater<YourDataClass, String>() { 
    @Override 
    public void update(int index, YourDataClass obj, String value) { 
    //Do stuff for click event. 
    } 
}); 

agentsTable.addColumn(columnValue, " "); 
agentsTable.setColumnWidth(columnValue, 10,com.google.gwt.dom.client.Style.Unit.PCT); 

添加下面的代碼在你的類的造型;

@UiField 
Style style; 
public interface Style extends CssResource { 
    String clickableText(); 
} 

添加下面的風格融入您ui.xml文件:

.clickableText{ 
    align: left; 
    color: blue; 
    text-decoration: underline; 
    } 

http://www.pandurangpatil.com/2014/03/gwt-access-style-defined-inside-uixml.html知道如何從ui.xml訪問的造型在你的類