-
Notifications
You must be signed in to change notification settings - Fork 39
/
BI.GridData.pas
99 lines (72 loc) · 3.44 KB
/
BI.GridData.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
{*********************************************}
{ TeeGrid Software Library }
{ TeeBI Virtual Data class }
{ Copyright (c) 2016-2017 by Steema Software }
{ All Rights Reserved }
{*********************************************}
unit BI.GridData;
interface
{
TBIGridData class enables connecting any TDataItem to a TeeGrid
Example:
uses BI.Persist, BI.DataSource, BI.GridData;
var Customers : TDataItem;
Data : TBIGridData;
Customers:= TStore.Load('SQLite_Demo')['Customers'];
Data:= TBIGridData.Create(Customers);
TeeGrid1.Data:= Data;
Optionally set a "Detail" to show it as sub-grid rows:
Data.Detail:= TStore.Load('SQLite_Demo')['Orders'];
Enable or disable column sorting (clicking Grid Header):
Data.Sortable:= False; // default is True
}
uses
System.Classes, System.TypInfo, System.Generics.Collections,
Tee.Grid, Tee.Grid.Columns, Tee.Painter, Tee.Renders, Tee.GridData,
BI.Data, BI.DataSource, BI.Data.RTTI;
type
TBIGridData=class(TVirtualData)
private
FCursor : TDataCursor;
FSortable : Boolean;
class function DataOf(const AColumn:TColumn):TDataItem; inline; static;
function GetData: TDataItem;
class procedure LinkTo(const AColumn: TColumn; const AItem:TDataItem); static;
function RowOf(const ARow:Integer):Integer;
procedure SetData(const Value: TDataItem);
procedure SetSortable(const Value: Boolean);
protected
Master : TDataItem;
function Empty:Boolean; override;
function KnownCount: Boolean; override;
procedure SetField(const AColumn:TColumn; const ASource:TObject); override;
public
Detail : TDataItem;
Constructor Create(const AProvider:TDataProvider); overload;
Constructor Create(const AItem:TDatAItem=nil); overload;
{$IFNDEF AUTOREFCOUNT}
Destructor Destroy; override;
{$ENDIF}
procedure AddColumns(const AColumns:TColumns); override;
function AsFloat(const AColumn:TColumn; const ARow:Integer):TFloat; override;
function AsString(const AColumn:TColumn; const ARow:Integer):String; override;
function AutoWidth(const APainter:TPainter; const AColumn:TColumn):Single; override;
function CanExpand(const Sender:TRender; const ARow:Integer):Boolean; override;
function CanSortBy(const AColumn:TColumn):Boolean; override;
class function ColumnOf(const AGrid:TCustomTeeGrid; const AItem:TDataItem):TColumn; static;
function Count:Integer; override;
class function From(const ASource:TComponent):TVirtualData; override;
class function From(const AData:TDataItem):TBIGridData; overload;
class function From<T>(const Value:Array of T):TBIGridData; overload; static;
class function From<T>(const Value:TList<T>):TBIGridData; overload; static;
function GetDetail(const ARow:Integer; const AColumns:TColumns; out AParent:TColumn): TVirtualData; override;
class function IsNumeric(const AColumn:TColumn):Boolean; override;
function IsSorted(const AColumn:TColumn; out Ascending:Boolean):Boolean; override;
procedure Load(const AColumns:TColumns); override;
procedure SetValue(const AColumn:TColumn; const ARow:Integer; const AText:String); override;
procedure SortBy(const AColumn:TColumn); override;
function DataType(const AColumn:TColumn):PTypeInfo; override;
property Data:TDataItem read GetData write SetData;
property Sortable:Boolean read FSortable write SetSortable default True;
end;
implementation