<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/htmlcharset=utf-8" />
<title>添加table列</title>
<script type="text/javascript" src="http://www.sz886.com/js/jquery-1.9.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function(e) {
$("#btn_row").click(function(){
$("#table_add tr").eq(0).append("<td>第"+($("#table_add tr:eq(0) td").size()+1)+"列</td>")
})
})
</script>
</head>
<body>
<table id="table_add">
<tr>
<td>第1列</td>
<td >第2列</td>
</tr>
</table>
<input type="button" id="btn_row" value="添加列" />
</body>
</html>
首先了解一下JSF中DataTable的渲染方式:DataTable--<Header UIComponent--<ChildrenList<HtmlColumn
----<HtmlColumn
------<HeaderUIComponent
----<ChildrenList<UIComponent
因此,要在后台变更DataTable的状态,可以用dt.setHeader(UIComponent)设置DataTable的表头,然后可以往dt.getChildren()中添加HtmlColumn类型的列,同样,列中也可以由Header和Children组成。
代码实现如下:
private void initialReportTable(List<ExcelReport reportList) {
dt.getChildren().clear()
for (ExcelReport report : reportList) {
HtmlColumn column = new HtmlColumn()
HtmlOutputText header = new HtmlOutputText()
header.setValueExpression("value",
getValueExpression("#{rmaReport.captions.c"
+ report.getPosition() + "}"))
column.setHeader(header)
HtmlOutputText value = new HtmlOutputText()
String ve = getVEString(report)
System.out.println(report.getCaption() + " : " + ve)
value.setValueExpression("value", getValueExpression(ve))
column.getChildren().add(value)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)