问题描述
好的,我有一个 CellTable
,它有 3 列和 2 行.我希望表格中某些特定单元格(不是所有单元格)中的文本为粗体.
请看这段代码:
ListDataProvider>dataProvider = new ListDataProvider>();dataProvider.addDataDisplay(table);列表>list = dataProvider.getList();列表sublist1= Arrays.asList("223","546","698");列表sublist2= Arrays.asList("123","876","898");列表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)
行 - 列0 - 10 - 21 - 11 - 22 - 2显然,我只想设置 5 个单元格的样式.
所以我确实像你说的那样:
在 css 文件中:
.boldRow .boldColumn { 字体粗细:粗体;}
然后在java文件中
column2.setCellStyleNames(getView().getRes().css().boldColumn());column3.setCellStyleNames(getView().getRes().css().boldColumn());table.setRowStyles(new RowStyles>() {@覆盖public String getStyleNames(List row, int rowIndex) {if(rowIndex==0 || rowIndex==1 || rowIndex==2){返回 getView().getRes().css().boldRow();}返回空;}});
这是结果:
Col1 - Col2 - Col3223 - 546 - 698123 - 876 - 898123 - 896 - 438显然,我不希望此单元格(行索引 = 2 & 列索引 = 3)加粗.但结果包括它.
那么如何解决呢?
找到我的帖子 如何根据该单元格的值 (GWT) 在 CellTable 中设置特定单元格的样式?.
这将解决您的问题.
在AbstractCell
...FontWeight 权重 = FontWeight.BOLD;if (context.getColumn()==0 || (context.getIndex()==1 && context.getColumn()==2)) {重量 = FontWeight.NORMAL;}...
Ok, i have a CellTable
that has 3 columns and 2 rows. I want the text in SOME specific cells (not all cell) in the table to be BOLD.
Please look at this code:
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");
I tried, it almost done, BUT...
Suppose I want to style the cell that is the intersection of the following Row Index and Column Index: (Note: index start from 0, so column2 got index=1)
Row - Col 0 - 1 0 - 2 1 - 1 1 - 2 2 - 2
Clearly, I just want to style 5 cells only.
So i did like you said:
in css file:
.boldRow .boldColumn { font-weight: bold; }
Then in the java file
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;
}
});
ANd here is the result:
Col1 - Col2 - Col3 223 - 546 - 698 123 - 876 - 898 123 - 896 - 438
Clearly, i don't want this cell (row index =2 & columm index=3) bold. But the result include it.
So how to fix it?
Find my post her How to style specific cells in CellTable depending the value of that cell (GWT)?.
This will solve your problem.
Use below code in AbstractCell
...
FontWeight weight = FontWeight.BOLD;
if (context.getColumn()==0 || (context.getIndex()==1 && context.getColumn()==2)) {
weight = FontWeight.NORMAL;
}
...
这篇关于如何设置作为单元格表(GWT)中行和列交叉点的单元格的样式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!