2013-07-11 34 views
1

我有一個靜態列的GWT數據網格。雖然我知道我可以刪除列並使用不同的名稱添加它們,但可以直接更改列的名稱嗎?如何更改GWT DataGrid中的列的名稱?

更新:

我不明白這是怎麼回事。根據Thomas Boyer的回答,我在文檔中看到.getHeader()從AbstractCellTable繼承爲公共方法,但編譯器說DataGrid不存在這樣的方法。創建

網:

DataGrid myGrid = new DataGrid<MyType>(Integer.MAX_VALUE, GWT.<DataGridResources2> create(DataGridResources2.class)); 

這無法編譯:

Header<MyHeaderClass> header = myGrid.getHeader(0); 

編譯器說,沒有這樣的方法存在類型的DataGrid。

回答

0

您可以使用數據網格的getHeader方法獲取列標題,然後

getCell().setValue 
+0

GWT DataGrid沒有getHeader()方法。 – CBass

+0

@CBass WAT? 'DataGrid'擴展'AbstractCellTable','AbstractCellTable'具有'getHeader'(請參閱答案中的鏈接) –

+0

我在文檔中看到getHeader是從AbstractCellTable公開繼承的,但編譯器說它沒有爲DataGrid類型定義。 – CBass

0

好像建議的答案是行不通的,因爲setValue方法不只是需要一個字符串或SafeHtml - 你需要的東西像上下文等

這裏有一個辦法做到這一點:

public class HeaderHtml implements SafeHtml { 
    /** 
    * the header's HTML string 
    */ 
    private String html = ""; 

    /** 
    * Sets the HTML after escaping tags. 
    * Could change to: 
    * this.html = html == null ? "" : html; 
    * if desired. 
    */ 
    public void setHtml(String html) { 
     this.html = html == null ? "" : SafeHtmlUtils.htmlEscapeAllowEntities(html); 
    } 

    /** 
    * Required method to deliver the HTML string 
    * @return the HTML string 
    */ 
    @Override 
    public String asString() { 
     return html; 
    } 
} 

創建者的一個實例作爲SafeHtml頭使用。然後,您可以隨時按下新字符串。