如果我的 TcxGrid 在 Delphi 中处于 GridMode True,我该如何使用过滤器

How can I use filters if my TcxGrid is on GridMode True in Delphi

我希望能够过滤加载到我的 TcxGrid 组件中的记录,我有 GridMode 因为网格在我的申请表上显示记录有点慢,但这种模式不会不要让我使用列的过滤器(只是默认的)。

我在官方论坛上找到的:

Filtering can be implemented by setting the Data Controller's Filter.AutoDataSetFilter property value to True. This way, the filter expression will be automatically applied to the underlying dataset. In the meantime, please note that the Grid working in Grid mode, does not create a list of the possible filter items in the column dropdown filter list. However, you may implement this yourself within the column's OnGetFilterDisplayText or OnGetFilterValues events or the Data Controller's OnGetValueList event. Please refer to the ExpressQuantumGrid's documentation to get more information about these events and how to use them.

但我不知道该怎么做,因为我找不到那些文档。任何帮助将不胜感激

DevExpress 拥有强大的支持团队,如果您需要有关他们产品的帮助,请联系他们。

总之,大体上,它的工作原理如下: 您可以使用列的 OnGetFilterValues 事件通过代码自由添加值:

procedure TForm1.cxGrid1DBTableView1MYFIELDGetFilterValues(
  Sender: TcxCustomGridTableItem; AValueList: TcxDataFilterValueList);
begin
  AValueList.Add(fviValue, 'Value A', 'Value A', False);
  AValueList.Add(fviValue, 'Value B', 'Value B', False);
  AValueList.Add(fviValue, 'Value C', 'Value C', False);
end;

设置 DataControllerFilter.AutoDataSetFilter 会导致底层 TDataSet.Filter 属性 自动填充相应的条件。例如:

ShowMessage(cxGrid1DBTableView1.DataController.DataSet.Filter);

((MYFIELD = 'Value A') OR (MYFIELD = 'Value B'))

这显然取决于您使用的 TDataSet 的后代 class 在 Filter 的 属性 发生变化时的反应。

如果您需要更大的灵活性,可以使用 DataController.Filter.OnBeforeChangeDataController.Filter.OnChanged 事件处理程序。