关键步骤:
1、设置DBGRID的summary.enabled:=true
2、打开DBGRID的columns字段,设置DBGRID对应的column的showsummary:=true;
3、写入uniDBGRID.onColumnSummary事件:
procedure TframeCalBBU.UniDBGrid1ColumnSummary(Column: TUniDBGridColumn;
GroupFieldValue: Variant);
begin
if sametext(column.FieldName,'BBU数量') or
sametext(column.FieldName,'总端口数') or
sametext(column.FieldName,'RRU占用端口数') or
sametext(column.FieldName,'空余端口数') then
begin
//计算分组合计
if Column.AuxValue=NULL then Column.AuxValue:=0;
Column.AuxValue:=Column.AuxValue + Column.Field.AsInteger;
//计算总计,这个需要grandTotal时候用。
// if Column.AuxValues[1]=NULL then Column.AuxValues[1]:=0;
// Column.AuxValues[1]:=Column.AuxValues[1] + Column.Field.AsInteger;
end;
end;
4、写入UniDBGridSummaryResult事件:
procedure TframeCalBBU.UniDBGrid1ColumnSummaryResult(Column: TUniDBGridColumn;
GroupFieldValue: Variant; Attribs: TUniCellAttribs; var Result: string);
var
I : Integer;
F : Real;
begin
if sametext(column.FieldName,'BBU机房') then
result:='合计:'
else
begin
i:=Column.AuxValue;
Result:=Format('%d', [I]);
end;
Attribs.Font.Style:=[fsBold];
Attribs.Font.Color:=clNavy;
Column.AuxValue:=NULL;
end;
5、需要grandTotal事件时候,写入对应事件
procedure TframeCalBBU.UniDBGrid1ColumnSummaryTotal(Column: TUniDBGridColumn;
Attribs: TUniCellAttribs; var Result: string);
var
i:integer;
begin
if sametext(column.FieldName,'BBU机房') then
result:='全部总计:'
else
begin
i:=Column.AuxValues[1];
Result:=Format('%d', [I]);
Attribs.Font.Style:=[fsBold];
Attribs.Font.Color:=clGray;
end;
end;