@Priv public void getDataTable(DataGridAction dga){ String tableID = $V( "TableID" ); DataTable dt = YearBookBL.getDataTable(tableID); Current.put( "_CurentDT" , dt); Response.put( "Columns" , dt.getDataColumns()); dga.bindData(dt); } |
把DataTable中的所有列放到Response中以供前台去获取动态表头
2.前台页面:
< z:datagrid id = "dg1" method = "YearDataManage.getDataTable" > < table width = "100%" cellpadding = "2" cellspacing = "0" class = "z-datagrid" > < tr ztype = "head" class = "dataTableHead" > < td width = "5%" ztype = "RowNo" >< z:lang id = "Common.SN" >序号</ z:lang ></ td > < td width = "4%" ztype = "selector" field = "ID" > </ td > < z:foreach data = "${Columns}" > < td >${value.ColumnName}</ td > </ z:foreach > </ tr > < tr onDblClick = "" class1 = "dg_tr_odd" class2 = "dg_tr_even" > < td > </ td > < td > </ td > < z:foreach data = "${_Zving_ZList_Data[i-1]}" count = "${length(Columns)}" > < td >${value}</ td > </ z:foreach > </ tr > </ table > </ z:datagrid > |
1).遍历Columns,动态获取表头
2)._Zving_ZList_Data 是ListTag标签内部静态属性,用于指定DataTable变量,该变量同时也被添加到DataGrid和DataList标签中
3).遍历_Zving_ZList_Data[i-1],获取dt中每一个单元格中所对应的值,length(Columns)限制列数,去掉了行号那一列
所有评论仅代表网友意见