之前用flex+c#做的一个项目中,有涉及到列的汇总计算。可以用到的方法很多,这里列举了一种,在前台flash中用footerdatagrid结合labelfunction的用法即可实现。当然,下面的代码实现的是每一列的所有行的汇总(由SUMcolum中的for循环可知),如果要实现每一列的奇数行(或偶数行或其他自定义挑选的行)的汇总,则需要稍作修改。

(不过,最后没用这种方法,而是在后台C#实体类中添加“合计”成员来实现。)

  xmlns:local="HZAssessment.TCJS.*" //声明自定义的组件local

  4             /**列汇总公共函数**/
private function SUMcolumn(column:DataGridColumn):String
{
var n:int = datalist.length;
var sum:Number = ;
for (var i:int = ; i < n; i++)
{
sum += datalist[i][column.dataField];
} return sum.toFixed();
} //土地正式列汇总
private function SUMsumTZ(column:DataGridColumn):String
{
return SUMcolumn(column); } //土地简式列汇总
private function SUMsumTJ(column:DataGridColumn):String
{
return SUMcolumn(column);
} //房产正式列汇总
private function SUMsumFZ(column:DataGridColumn):String
{
return SUMcolumn(column);
} //房产简式列汇总
private function SUMsumFJ(column:DataGridColumn):String
{
return SUMcolumn(column);
} //房拆正式列汇总
private function SUMsumFCZ(column:DataGridColumn):String
{
return SUMcolumn(column); }
//房拆简式列汇总
private function SUMsumFCJ(column:DataGridColumn):String
{
return SUMcolumn(column);
} //合计正式列汇总
private function SUMsumHJZS(column:DataGridColumn):String
{
return SUMcolumn(column);
} //合计简式列汇总
private function SUMsumHJJS(column:DataGridColumn):String
{
return SUMcolumn(column);
} <local:FooterDataGrid id="dg_shtjlist" initialize="dg_shtjlist.dataProvider ='{datalist}'" width="100%" height="100%" paddingTop="" paddingBottom="" verticalAlign="middle" >
<local:columns>
<local:FooterDataGridColumn id="shr" headerText="审核人" dataField="zsrxm">
<mx:DataGridColumn headerText="汇总" dataField="zsrxm" />
</local:FooterDataGridColumn>
<local:FooterDataGridColumn id="tz" headerText="土地正式" dataField="sumTZ" >
<mx:DataGridColumn dataField="sumTZ" labelFunction="SUMsumTZ" />
</local:FooterDataGridColumn>
<local:FooterDataGridColumn id="tj" headerText="土地简式" dataField="sumTJ" >
<mx:DataGridColumn labelFunction="SUMsumTJ" dataField="sumTJ" />
</local:FooterDataGridColumn>
<local:FooterDataGridColumn id="fz" headerText="房产正式" dataField="sumFZ" >
<mx:DataGridColumn labelFunction="SUMsumFZ" dataField="sumFZ" />
</local:FooterDataGridColumn>
<local:FooterDataGridColumn id="fj" headerText="房产简式" dataField="sumFJ" >
<mx:DataGridColumn labelFunction="SUMsumFJ" dataField="sumFJ" />
</local:FooterDataGridColumn>
<local:FooterDataGridColumn id="fcz" headerText="房拆正式" dataField="sumFCZ" >
<mx:DataGridColumn labelFunction="SUMsumFCZ" dataField="sumFCZ" />
</local:FooterDataGridColumn>
<local:FooterDataGridColumn id="fcj" headerText="房拆简式" dataField="sumFCJ" >
<mx:DataGridColumn labelFunction="SUMsumFCJ" dataField="sumFCJ" />
</local:FooterDataGridColumn> <local:FooterDataGridColumn id="hjzs" headerText="合计(正式)" dataField="sumHJZS" labelFunction="HJZSlabel" color="#8A2BE2" >
<mx:DataGridColumn labelFunction="SUMsumHJZS" dataField="sumHJZS" color="#8A2BE2" />
</local:FooterDataGridColumn> <local:FooterDataGridColumn id="hjjs" headerText="合计(简式)" dataField="sumHJJS" labelFunction="HJJSlabel" color="#8A2BE2" >
<mx:DataGridColumn labelFunction="SUMsumHJJS" dataField="sumHJJS" color="#8A2BE2"/>
</local:FooterDataGridColumn> </local:columns>
</local:FooterDataGrid>
05-02 18:45