如何使用GXT 3网格将网格列渲染为多线网格列。
e.g
ColumnConfig<ExceptionEntry, String> name = new ColumnConfig<ExceptionEntry, String>(props.name(), 50, "Name");
name.setColumnStyle(new SafeStyles(){
@Override
public String asString() {
return // what styles to use for multiline rendering;
}
});
name.setCell(new AbstractCell<String>() {
@Override
public void render(com.google.gwt.cell.client.Cell.Context context,
String value, SafeHtmlBuilder sb) {
??? what needs to be done to render the column as multiline column
}
});
答案 0 :(得分:2)
你可以轻松而艰难地做到这一点。
简单的一个:
name.setCell(new AbstractCell<String>() {
@Override
public void render(com.google.gwt.cell.client.Cell.Context context, String value, SafeHtmlBuilder sb) {
sb.appendHtmlConstant("<div style=\"white-space: normal;\" >" + value + "</div>");
}
});
艰难(但更好)的方式:
1)创建要使用的自定义GridAppearance
,而不是主题中的默认值:{/ p>
import com.google.gwt.core.client.GWT;
import com.sencha.gxt.theme.base.client.grid.GridBaseAppearance;
public class YourGridAppearance extends GridBaseAppearance {
public interface YourGridStyle extends GridStyle {
}
public interface YourGridResources extends GridResources {
@Source({ "com/sencha/gxt/theme/base/client/grid/Grid.css", "YourGrid.css" })
@Override
YourGridStyle css();
}
public YourGridAppearance() {
this(GWT.<YourGridResources> create(YourGridResources.class));
}
public YourGridAppearance(YourGridResources resources) {
super(resources);
}
}
2)将/theme-you-use/client/grid/Grid.css
复制到YourGrid.css
并将其放在您创建YourGridAppearance
课程的同一文件夹中。以下是基于灰色主题的示例:
@CHARSET "UTF-8";
.rowHighlight {
border: 1px dotted #535353;
}
.rowAlt .cell {
background-color: #FAFAFA;
}
.rowOver .cell {
background-color: #EEEEEE;
}
.cell {
border-color: #FAFAFA #EDEDED #EDEDED;
border-right: 0 solid #EDEDED;
font: 14px tahoma,arial,verdana,sans-serif;
}
.cellSelected {
background-color: #C9C9C9 !important;
color: #000000;
}
.cellInner {
white-space: normal;
line-height: 15px;
}
.columnLines .cell {
border-right-color: #EDEDED;
}
.rowOver .cell,.rowOver .rowWrap {
border-color: #DDDDDD;
}
.rowWrap {
border-color: #FAFAFA #EDEDED #EDEDED;
border-right: 0 solid #EDEDED;
border-style: solid;
border-width: 1px;
overflow: hidden;
}
.rowSelected .cell,.rowSelected .rowWrap {
background-color: #DFE8F6 !important;
border-color: #A3BAE9;
}
.footer {
background: #F7F7F7 none repeat scroll 0 0;
border-top: 1px solid #DDDDDD;
border-bottom: 1px solid #DDDDDD;
display: block;
overflow: hidden;
position: relative;
}
最重要的部分是这一个:
.cellInner {
white-space: normal;
}
3)用您的自定义网格替换默认网格外观。为此,您必须将以下行添加到 your-project.gwt.xml :
<replace-with class="package.name.of.your.custom.theme.class.YourGridAppearance">
<when-type-is class="com.sencha.gxt.widget.core.client.grid.GridView.GridAppearance" />
</replace-with>