[英]How to style a Row of CellTable when user click on a Cell (GWT)?
[英]How to style the cell that is the intersection of row and column in celltable (GWT)?
好的,我有一個CellTable
,它具有3列和2行。 我希望表中某些特定單元格(不是所有單元格)中的文本為粗體。
請看下面的代碼:
ListDataProvider<List<String>> dataProvider = new ListDataProvider<List<String>>();
dataProvider.addDataDisplay(table);
List<List<String>> list = dataProvider.getList();
List<String> sublist1= Arrays.asList("223","546","698");
List<String> sublist2= Arrays.asList("123","876","898");
List<String> sublist2= Arrays.asList("123","896","438");
IndexedColumn column1=new IndexedColumn(0);
table.addColumn(column1, "Col1");
IndexedColumn column2=new IndexedColumn(1);
table.addColumn(column2, "Col2");
IndexedColumn column3=new IndexedColumn(2);
table.addColumn(column3, "Col3");
我嘗試了,差不多完成了,但是...
假設我要設置以下行索引和列索引的交集的單元格的樣式:(注意:索引從0開始,所以column2的索引為= 1)
Row - Col 0 - 1 0 - 2 1 - 1 1 - 2 2 - 2
顯然,我只想設置5個單元格的樣式。
所以我確實喜歡你說的:
在css文件中:
.boldRow .boldColumn { font-weight: bold; }
然后在java文件中
column2.setCellStyleNames(getView().getRes().css().boldColumn());
column3.setCellStyleNames(getView().getRes().css().boldColumn());
table.setRowStyles(new RowStyles<List<String>>() {
@Override
public String getStyleNames(List<String> row, int rowIndex) {
if(rowIndex==0 || rowIndex==1 || rowIndex==2){
return getView().getRes().css().boldRow();
}
return null;
}
});
結果如下:
Col1 - Col2 - Col3 223 - 546 - 698 123 - 876 - 898 123 - 896 - 438
顯然,我不希望此單元格(行索引= 2&列索引= 3)加粗。 但是結果包括了它。
那么如何解決呢?
在我的帖子中找到她如何根據單元格(GWT)的值在CellTable中設置特定單元格的樣式? 。
這樣可以解決您的問題。
在AbstractCell
使用以下代碼
...
FontWeight weight = FontWeight.BOLD;
if (context.getColumn()==0 || (context.getIndex()==1 && context.getColumn()==2)) {
weight = FontWeight.NORMAL;
}
...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.