2011-04-27 5 views
7

셀에 HTML 코드를 넣으려는 CellTable이 있습니다. 다음 코드는 작동하지 않으며 공백은 출력에서 ​​제거됩니다.GWT - CellTable 셀에 HTML을 사용하게 하시겠습니까?

TextColumn<MyCell> column1 = new TextColumn<MyCell>() 
    { 
     @Override 
     public String getValue(MyCell myCell) 
     { 
      String result = "  " +myCell.getValue(); 
      return result; 
     } 
    }; 
    table.addColumn(column1 , "Header1"); 

저는 CSS를 사용하여이를 수행 할 수 있지만 HTML 코드를 셀에 넣는 방법을 알고 싶습니다. 어떤 도움을 주셔서 감사합니다!

답변

16

AFAIK 추가 공백은 HTML에서 무시됩니다. 서식을 유지하려면 pre 태그를 사용해야합니다. 어쨌든 아래 내 견본을 찾으십시오. 데이터 공급자가 지원하는 객체에 포함 된 값에서 멋진 진행률 표시 줄을 생성합니다.

final SafeHtmlCell progressCell = new SafeHtmlCell(); 

    Column<UiScheduledTask, SafeHtml> progressCol = new Column<UiScheduledTask, SafeHtml>(
      progressCell) { 

     @Override 
     public SafeHtml getValue(UiScheduledTask value) { 
      SafeHtmlBuilder sb = new SafeHtmlBuilder(); 
      float percent = new Float(value.getCompleted()) 
        /new Float(value.getAll()); 
      int rounded = Math.round(percent * 100); 
      sb.appendHtmlConstant("<div style='width: 100px; height: 20px; position: relative;'>"); 
      sb.appendHtmlConstant("<div style='z-index: 2; display: inline; width: 100px; position: absolute; left: 0px, top: 0px; text-align: center;'>" 
        + value.getCompleted() 
        + "/" 
        + value.getAll() 
        + "</div>"); 
      sb.appendHtmlConstant("<div style='position: absolute; left: 0; top: 0; width: 100px; z-index: 1'><div style='display: inline; float: left; width: " 
        + rounded 
        + "%; height: 20px; background-color: #82cd80;'></div>"); 
      sb.appendHtmlConstant("<div style='display: inline; float: right; width: " 
        + (100 - rounded) 
        + "%; height: 20px; background-color: #c54c4d;'></div></div>"); 
      sb.appendHtmlConstant("</div>"); 
      return sb.toSafeHtml(); 
     } 
    }; 
+0

감사합니다. jgrabowski! 이것은 완벽하게 작동합니다! 그리고 예, pre 태그를 사용하지 않으면 HTML에서 추가 공백이 무시됩니다. – gusper

+0

고마워,이게 내가 찾고있는거야. –

+0

  엔터티 태그도 작동 할 수 있습니다. –

관련 문제