cxgrid过滤使用心得

[delphi] view plain copy
 
  1. uses cxFilter;  
cxgrid过滤条件清除:cxgrdbtblvwGrid1DBTableView2.DataController.Filter.AutoDataSetFilter:=True;
                                     cxgrdbtblvwGrid1DBTableView2.DataController.Filter.Clear;
cxgrid过滤条件添加:cxgrdbtblvwGrid1DBTableView2.DataController.Filter.Root.Clear;

[delphi] view plain copy
 
  1. cxgrdbtblvwGrid1DBTableView2.DataController.Filter.Root.AddItem(cxgrdbtblvwGrid1DBTableView2.GetColumnByFieldName('合同号'),folike,'%'+hth+'%','%'+hth+'%');  
  2. cxgrdbtblvwGrid1DBTableView2.DataController.Filter.Active:=True ;  
 
CXGRID程序控制过滤方法:
[delphi] view plain copy
 
  1. DBTable.DataController.Filter.Root.Clear;  
  2. // DBTable.DataController.Filter.Root.BoolOperatorKind过滤关系【有四个值】  
  3. DBTable.DataController.Filter.Root.BoolOperatorKind:= fboOR;//或者  
  4. DBTable.DataController.Filter.Root.BoolOperatorKind:= fboAND;//并且  
  5. DBTable.DataController.Filter.Root.BoolOperatorKind:= fboNOTOR;//非或者  
  6. DBTable.DataController.Filter.Root.BoolOperatorKind:= fboNOTAND;//非并且  
  7. //DBTable.DataController.Filter.Root.AddItem(AItemlink:Tobject;Aoperatorkind:Tcxfilteroperator;Const Avalue:variant;const Adisplayvalue:STRING);  

相应说明:
AItemlink=列
Aoperatorkind=条件
foequal        等于
fonotequals        不等于
foless        小于
folessequal        小于等于
fogreater        大于
fogreaterequal        大于等于
oflike        相似
ofnotlike        不相似
    ofblank        为空
    ofnotblank        不为空
Avalue=条件值
Adisplayvalue=显示值
DBTable.DataController.Filter.Active:=TRUE;

//由上面可得出一个过程:
PROCEDURE DATA_ADDITEM(CXDATA:TcxGridDBDataController;Index,IfInt:integer;VarStr,PlaStr:String);
Var IfStr:TcxFilterOperatorKind;
Begin
  Case IfInt Of
      0: IfStr:= foEQUALS;
      2: IfStr:=foNOTEQUALS;
      3: IfStr:=foLESS;
      4: IfStr:=foLESSEQUAL;
5: IfStr:=foGREATER;
      6: IfStr:=foGREATEREQUAL;
      7: IfStr:=ofLIKE;
      8: IfStr:=ofNOTLIKE;
      9: IfStr:=ofBLANK;
      10:IfStr:=ofNOTBLANK;
  End;
CXDATA.ROOT.AddItem(CXDATA.Columns[Index],IfStr,VarStr,PlaStr)
End;
 
[delphi] view plain copy
 
  1. uses cxFilter;  
  2.   
  3.   
  4.   
  5.       with cxGridDBBandedTableView.DataController.Filter do  
  6.         begin  
  7.           Root.Clear;  
  8.           Root.AddItem(cxGridDBBandedTableView.GetColumnByFieldName('操作员姓名'), foLike, '%' + Trim(cxTextEdit.Text) + '%', '%' + Trim(cxTextEdit.Text) + '%');  
  9.           Active := True;  
  10.         end;  
 
设置过滤的案例:
[delphi] view plain copy
 
  1. <AGridView>.DataController.Filter.AddItem(nil, <AOrderDateColumn>, foEqual, '5/25/1988', '5/25/1988');  
  2. To enable/disable filtering via code set the GridView's DataController.Filter.Active property to True.  
  3.       
  4. [Delphi]Open in popup window  
  5. <AGridView>.DataController.Filter.Active := False;  
原文地址:https://www.cnblogs.com/westsoft/p/8643783.html