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. idea部署tomcat-404错误

    今天在部署数据质量web工程在tomcat后,访问时报404错误,在网上搜了很多相关配置,也都是一步一步来的 Application Context 也配置好了,Artifact也添加了,就是访问不了 ...

  2. Maximum Average Subarray II LT644

    Given an array consisting of n integers, find the contiguous subarray whose length is greater than o ...

  3. vuejs导航条动态切换active状态

    用一个数组存导航条,用v-for循环它,这样可以减少代码,二可以使用它的下标来判断高亮,三还可以获取后端的导航信息来遍历 重点是在:routerLink(index, path)函数,传入当前点击的下 ...

  4. ios 内存管理与property copy strong weak assign

    - (void)fun{  NSString* str = [[NSString alloc] initWithString:@"string"];  NSLog(@"% ...

  5. Java第3章笔记

    if基本语法: if(条件){// 表达式   // 代码块   } eg:    int a = 10;    if(a > 1){  System.out.println("内容& ...

  6. SpringMVC作用域传值几种方式

    一.SpringMVC 作用域传值的几种方式 1  使用原生Servlet 1.1 在 HandlerMethod 参数中添加作用域对象 1.1.1 ServletContext不能在方法参数中获取, ...

  7. log4j介绍和使用

    1.apache推出的开源免费日志处理的类库 2.为什么需要日志?? 2.1 在项目中编写system.out.println();输出到控制台,当项目发布到tomcat后,没有控制台(在命令界面能看 ...

  8. C++中1/0和1/0.0的区别

    参考:https://zhidao.baidu.com/question/1494117716904764979.html 问题说明:在Dev中1/0会报错“除数不得为0”,但是1/0.0不报错,并且 ...

  9. 百度地图足迹demo(多点轨迹生成)

    不要忘记引用JQuery//~~~<script src="jquery-1.7.1.min.js" type="text/javascript"> ...

  10. mysql学习之路_字段类型与属性2

    字段属性: 主键,唯一键,自增长. 主键: Primary key 主要的键,一张表只能有一个字段能使用对应的键,用来唯一约束该字段里面的数据不能重复,称之为主见. 一张表最多只有一个主键. 增加主键 ...