http://bbs.csdn.net/topics/390536919

关于 cxGrid 的过滤问题 [问题点数:20分,结帖人zhengyc653]

           
不显示删除回复
           
显示所有回复
           
显示星级回复
           
显示得分回复
           
只显示楼主
          收藏
 
zhengyc653 

 
结帖率:95.45%
本帖最后由 zhengyc653 于 2013-08-03 15:17:16 编辑
 

今天用了一下cxGrid的过滤功能,非常强大,非常喜欢!
可是有一个缺点,他的运算符里面只有 like ,没有包含。
比如:我要找一个姓名包含‘国’字的人。
运算符必须得选 like 表达式则是:%国%
这样很多人就不懂得用了。

如何使它无需加%%就能过滤出名字包含'国'的人?

 
发表于: 2013-08-03 15:14:15 楼主

回复次数:14

CSDN推荐
董董 

 
用户输入“国”,你的代码就要包上%号。
回复于: 2013-08-03 15:23:17#1 得分:0

 
zhengyc653 

 
引用 1 楼 ddqqyy 的回复:

用户输入“国”,你的代码就要包上%号。

关键是在哪里的代码加上%号?

回复于: 2013-08-03 15:38:26#2 得分:0

 
董董 

 
用户输入查询条件之后,一般都要再点击一个“查询”按钮才开始查询吧?

你就在按钮事件中加%嘛。

回复于: 2013-08-03 15:45:31#3 得分:0

 
zhengyc653 

 
引用 3 楼 ddqqyy 的回复:

用户输入查询条件之后,一般都要再点击一个“查询”按钮才开始查询吧?

你就在按钮事件中加%嘛。

这个查询对话框要cxGrid自带的,不是我们自己设计的啊

回复于: 2013-08-03 15:47:52#4 得分:0

 
22222bbb 

 
二楼没明白楼主的意思。同求解决方法
回复于: 2013-08-03 15:52:58#5 得分:0

 
zhengyc653 

 
自己顶一下.... 难道没人遇到这个问题?
回复于: 2013-08-06 08:26:33#6 得分:0

 
simonhehe 

 
  
lz的需求, 只能改dev的代码实现

like的匹配情况有: %国%   国%   %国
你需求的[包含], 匹配情况只有: %国%

回复于: 2013-08-06 10:24:08#7 得分:0

 
zhengyc653 

 
引用 7 楼 simonhehe 的回复:

lz的需求, 只能改dev的代码实现

like的匹配情况有: %国%   国%   %国
你需求的[包含], 匹配情况只有: %国%

我也不知道要改Dev的代码,可跟踪来跟踪去,就是不知道要在哪改!

回复于: 2013-08-06 10:41:35#8 得分:0

 
zhengyc653 

 
思路:
应该在过滤窗体中找到确定这个按钮,然后更改生成出来的过滤字串。
于是,找到 cxFilterControlDialog.pas  ,查看 OK 按钮的 OnClick 事件
发现里面只有一条语句: 
ApplyFilter;
于是,再跟踪 ApplyFilter 函数,它的声明如下: 
procedure ApplyFilter; virtual;

Delphi/Pascal code

 

?

1
2
3
4
5
6
7
8
9
10
11
procedure TfmFilterControlDialog.ApplyFilter;
begin
  SetControlsEnabled(False);
  DoBeforeApply;
  try
    FilterControl.ApplyFilter;
  finally
    DoAfterApply;
    SetControlsEnabled(True);
  end;
end;

继续跟踪 DoBeforeApply ,发现其也是一个虚方法:

Delphi/Pascal code

 

?

1
2
3
4
5
procedure TfmFilterControlDialog.DoBeforeApply;
begin
  if Assigned(FOnBeforeApply) then
    FOnBeforeApply(Self);
end;

又发现 FOnBeforeApply 的声明为:
FOnBeforeApply: TNotifyEvent;
到这,就不懂得如何往下跟踪了...  

回复于: 2013-08-06 10:53:58#9 得分:0

 
zhengyc653 

 
filterControl.ApplyFilter;
filterControl 这个对象在哪? 在这个单元好像没找到这个对象
不知道是引引哪个单元的东东
回复于: 2013-08-06 11:02:16#10 得分:0

 
simonhehe 

 
  
1 把这个文件复制到你的程序目录
\DevExpress VCL\ExpressDataController\Sources\cxFilter.pas

2 TcxFilterCriteria.AddItem过程做如下修改:(自动给like, not like运算的查询条件加%)

Delphi/Pascal code

 

?

1
2
3
4
5
6
7
8
9
10
11
12
function TcxFilterCriteria.AddItem(AParent: TcxFilterCriteriaItemList; AItemLink: TObject;
  AOperatorKind: TcxFilterOperatorKind; const AValue: Variant;
  const ADisplayValue: string): TcxFilterCriteriaItem;
begin
  if AParent = nil then
    AParent := Root;
 
  if AOperatorKind in [foLike, foNotLike] then
    Result := AParent.AddItem(AItemLink, AOperatorKind, '%' + AValue + '%', ADisplayValue)
  else
    Result := AParent.AddItem(AItemLink, AOperatorKind, AValue, ADisplayValue);
end;
回复于: 2013-08-06 17:52:49#11 得分:0

 
zhengyc653 

 
引用 11 楼 simonhehe 的回复:

1 把这个文件复制到你的程序目录
\DevExpress VCL\ExpressDataController\Sources\cxFilter.pas

2 TcxFilterCriteria.AddItem过程做如下修改:(自动给like, not like运算的查询条件加%)

Delphi/Pascal code

 

?

1
2
3
4
5
6
7
8
9
10
11
12
function TcxFilterCriteria.AddItem(AParent: TcxFilterCriteriaItemList; AItemLink: TObject;
  AOperatorKind: TcxFilterOperatorKind; const AValue: Variant;
  const ADisplayValue: string): TcxFilterCriteriaItem;
begin
  if AParent = nil then
    AParent := Root;
 
  if AOperatorKind in [foLike, foNotLike] then
    Result := AParent.AddItem(AItemLink, AOperatorKind, '%' + AValue + '%', ADisplayValue)
  else
    Result := AParent.AddItem(AItemLink, AOperatorKind, AValue, ADisplayValue);
end;

非常感谢这位仁兄的帮助,问题解决了一半,按照你的方法,确实可行,但只适用于这个界面:

对于下面这个界面没有效果:

回复于: 2013-08-06 22:56:45#12 得分:0

 
simonhehe 

 
  
之前的修改全部取消.

一下改动完成后, 所有使用该文件做过滤的, like, not like 都会受影响
-------------------------------------------------------
把这个文件复制到你的程序目录
\DevExpress VCL\ExpressDataController\Sources\cxLike.pas

function LikeStr(const AStr, APatternStr: string; APercent, AUnderline: Char): Boolean;
var
  vPatternStr : string;
begin
  vPatternStr := Format('%%%s%%', [APatternStr]);
  Result := Like(PChar(AStr), Length(AStr), PChar(vPatternStr),
    Length(vPatternStr), APercent, AUnderline, #0);
end;

回复于: 2013-08-07 09:14:21#13 得分:20

 
zhengyc653 

 
非常感谢 simonhehe 的热心助助!!问题解决,分不多,全给你了。

关于 cxGrid 的过滤问题的更多相关文章

  1. cxgrid取消过滤下拉框

    选择tableview1.optionscustomize.columnfiltering=fasle;

  2. cxgrid的过滤%x%问题【备查】

    把这个文件复制到你的程序目录\DevExpress VCL\ExpressDataController\Sources\cxLike.pas function LikeStr(const AStr,  ...

  3. cxgrid过滤使用心得

    uses cxFilter; cxgrid过滤条件清除:cxgrdbtblvwGrid1DBTableView2.DataController.Filter.AutoDataSetFilter:=Tr ...

  4. cxgrid属性说明,每次用的时候费时费力查找。

    由层得到数据表名: procedure TFB_PatientWaiting.cxgrdbtblvwGrid1DBTableView_MyPatienWaitingDblClick( Sender: ...

  5. cxGrid控件过滤筛选后如何获更新筛选后的数据集

    cxGrid控件过滤筛选后如何获更新筛选后的数据集 (2015-06-19 12:12:08) 转载▼ 标签: delphi cxgrid筛选数据集 cxgrid过滤 分类: Delphi cxGri ...

  6. cxGrid实现取消过滤和排序后定位到首行(单选和多选)

    cxGrid实现取消过滤和排序后定位到首行(单选和多选) 原创 2013年10月06日 18:42:24 2107 DataContoller中的函数FocusedRecordIndex没有反应,Fo ...

  7. cxGrid控件过滤排序和TClientDataSet同步

    https://www.cnblogs.com/false/archive/2013/02/24/2924240.html procedure TReport10Form.cxGridViewData ...

  8. 如何访问cxGrid控件过滤后的数据集

    var I: Integer; begin Memo1.Lines.Clear; with cxGrid1DBTableView1.DataController do for I := 0 to Fi ...

  9. CXGrid的使用技巧

    CXGrid的使用技巧 ========================================================================== 在主从TableView中 ...

随机推荐

  1. PHP学习笔记(二)

    1.表单 PHP 的 $_GET和 $_POST用于检索表单中的值,比如用户输入. $_GET和$_POST变量分别用于收集来自 method="get" 和method=&quo ...

  2. python 截取某一天的日志,简单操作

    #!/usr/bin/python #Filename: Segmentation_log.py import re,sys def openfile(*args): try: f=open(args ...

  3. Why Linux Doesn’t Need Defragmenting

    If you’re a Linux user, you’ve probably heard that you don’t need to defragment your Linux file syst ...

  4. Spring 循环引用(一)一个循环依赖引发的 BUG

    Spring 循环引用(一)一个循环依赖引发的 BUG Spring 系列目录(https://www.cnblogs.com/binarylei/p/10198698.html) Spring 循环 ...

  5. SPring中quartz的配置(可以用实现邮件定时发送,任务定时执行,网站定时更新等)

    http://www.cnblogs.com/kay/archive/2007/11/02/947372.html 邮件或任务多次发送或执行的问题: 1.<property name=" ...

  6. [ES]ES集群内容灾

    ES是如何实现节点容灾的? 1. ES中的index,首先会进行分片,每一个分片数据一般都会有自己的副本数据,ES分配分片的策略会保证同一个分片数据和自己的副本不会分配到同一个节点上2. 当集群中的某 ...

  7. JVM新生代到老年代基础了解

    JVM区域总体分两类,heap区和非heap区. heap区又分为: - Eden Space(伊甸园). - Survivor Space(幸存者区). - Old Gen(老年代). 1个Eden ...

  8. 一窥kbmmw中的 smart service

    在kbmmw 的新版中(还没有发布),将会有一个叫做smart service 的服务.这种服务的属性基于服务器端,并且可以自动注册服务名,下面就是一个简单例子代码.这个服务里面有有三个发布的函数:e ...

  9. hadoop mapreduce 写入hbase报错 Session 0x0 for server null, unexpected error, closing socket connection and attempting reconnect

    现象:map任务构造数据正常,reduce任务,开始也正常,速度很快 ,在hbase 的管理界面,可以看到,5W以上的请求数 当reduce 执行到 70% 左右的时候,就堵住了,查看yarn的web ...

  10. c# DirectoryInfo 类和 FileInfo 类

    1.DirectoryInfo 类 DirectoryInfo 类派生自 FileSystemInfo 类.它提供了各种用于创建.移动.浏览目录和子目录的方法.该类不能被继承. 2.FileInfo ...