找回密码
 立即注册

QQ登录

只需一步,快速开始

Richard.Ma 讲师达人认证 悬赏达人认证 SpreadJS 开发认证
超级版主   /  发表于:2020-3-24 10:12  /   查看:2593  /  回复:0
本帖最后由 Richard.Ma 于 2020-3-24 10:55 编辑

在使用Flexgrid时,我们可以用它内置的过滤器来进行数据过滤,但是这个过滤器使用需要点开过滤弹窗后设置条件,相对麻烦一些

如果想要直接在表格中使用首行作为过滤行,开发包中提供了一个示例“ComponentOne Samples\WinForms\v4.5.2\C1FlexGrid\CS\FilterRow
可以根据首字母来进行过滤,过滤后效果如下


这个基本上可以实现我们的需求,但是还是有一个问题,无法实现模糊过滤(全字匹配)
这个问题我们可以通过修改以下的代码来改变过滤方式

  1.   private string BuildFilterExpression(int col, string expr)
  2.                 {
  3.                         // operators we recognize
  4.                         string oper = "<>=";

  5.                         // no operators? use 'like' for strings, = for other types
  6.                         if (oper.IndexOf(expr[0]) < 0)
  7.                         {
  8.                 return (_flex.Cols[col].DataType == typeof(string))
  9.                     ? string.Format(" like '*{0}*'", expr)
  10.                     : string.Format(" = '{0}'", expr);
  11.             }
  12.                         
  13.                         // look for end of operators
  14.                         for (int index = 0; index < expr.Length; index++)
  15.                         {
  16.                                 if (oper.IndexOf(expr[index]) < 0)
  17.                                 {
  18.                                         string retval = expr.Substring(0, index) + " ";
  19.                                         retval += string.Format("'{0}'", expr.Substring(index).Trim());
  20.                                         return retval;
  21.                                 }
  22.                         }

  23.                         // if we got here, the condition must be bad (e.g. ><)
  24.                         Debug.WriteLine("Can't build filter expression.");
  25.                         return "";
  26.                 }
复制代码



本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x

0 个回复

您需要登录后才可以回帖 登录 | 立即注册
返回顶部