UNIGUI-DBGRID的統計行的使用

關鍵步驟:html

一、設置DBGRID的summary.enabled:=trueurl

二、打開DBGRID的columns字段,設置DBGRID對應的column的showsummary:=true;orm

三、寫入uniDBGRID.onColumnSummary事件:htm

procedure TframeCalBBU.UniDBGrid1ColumnSummary(Column: TUniDBGridColumn;​blog

  GroupFieldValue: Variant);事件

beginget

if sametext(column.FieldName,'BBU數量') orstring

   sametext(column.FieldName,'總端口數') orim

   sametext(column.FieldName,'RRU佔用端口數') orimg

   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;

四、寫入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;

​​

五、須要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;

相關文章
相關標籤/搜索