TTMSFNCDataGrid filter editor questions

Hi,

I have two questions regarding the filtering.

  1. If I apply filtering and a gfcEditor through Grid.Options.Filtering, how do I get access to the controls created? For example, when I call .ClearFilter, I want the text in a string field filter editor to be blanked (as otherwise the filters are all removed but the controls are not reset).

  2. Can I add to the default controls? E.g., the date picker editor has no clear filter button (like the one the string filter editor has). Is it possible to add a button to the existing control?

Thanks!

Yes. The filter-row controls are accessible through:

Grid.FilterEditors[AColumn, Grid.Options.Filtering.Row]
Grid.HasFilterEditor[AColumn, Grid.Options.Filtering.Row]

For the built-in editors, that control is usually a TTMSFNCDataGridFilterPanel. The actual edit/date/spin/checkbox control is inside Panel.Editor.

uses
  VCL.TMSFNCDataGridRenderer, VCL.TMSFNCDataGridCell, VCL.TMSFNCEdit;

procedure TForm1.ClearFiltersAndEditors;
var
  C, R: Integer;
  E: TTMSFNCDataGridCellControl;
begin
  Grid.ClearFilter;

  R := Grid.Options.Filtering.Row;

  for C := 0 to Grid.ColumnCount - 1 do
    if Grid.HasFilterEditor[C, R] then
    begin
      E := Grid.FilterEditors[C, R];

      if E is TTMSFNCDataGridFilterPanel then
        TTMSFNCDataGridFilterPanel(E).Reset;
    end;
end;

You can also hook creation:

procedure TForm1.GridAfterCreateFilterEditor(Sender: TObject;
  ACell: TTMSFNCDataGridCellCoord; AEditor: TTMSFNCDataGridCellControl);
var
  P: TTMSFNCDataGridFilterPanel;
begin
  if AEditor is TTMSFNCDataGridFilterPanel then
  begin
    P := TTMSFNCDataGridFilterPanel(AEditor);

    // Gives access to built-in parts:
    // P.Editor
    // P.ClearButton
    // P.TypeButton

    P.AutoHideControls := False; // keeps clear/type buttons visible when narrow
  end;
end;

About adding to the default controls: yes, technically you can parent extra controls to the TTMSFNCDataGridFilterPanel in OnAfterCreateFilterEditor, but the panel’s own resize logic only manages its built-in Editor, TypeButton, and ClearButton. For anything more than a small tweak, gfetCustom plus OnCreateCustomFilterEditor is the cleaner route.

For the date picker: the built-in filter panel already has a ClearButton, but it auto-hides when the column is too narrow. Set AutoHideControls := False or widen the column. In VCL, though, the date editor is a TDateTimePicker, so it cannot really display a blank value; the built-in reset sets it to Now while removing the filter. If you need a visually blank date filter, use a custom filter editor.