TMSFNCDataGrid programmable filter the grid

My FNCDataGrid is connected to a Databaseadapter but i want to filter only with the grid not with the the dataset.
i want to filter the Column LastName and FirstName in a TAdvEditbox with te event edtName.change
How to filter with two columns in the FNCDataGrid.
Do you have a sample code.

Filtering with the grid/adapter and not with the dataset is only possible when setting LoadMode := almAllRecords.

For filtering, please take a look here, it bundles all resources related to data grid.

This is my try but it show all lastname persons after i have a ',' in the searchstring.

// Suchen mit edtSuche
procedure TfrmKunden.edtSucheChange(Sender: TObject);
var
  Suchbegriff, Nachname, Vorname: string;
  SepPos: Integer;
begin
  Suchbegriff := Trim(edtSuche.Text);
  GridKunden.Filter.Clear;

  if Suchbegriff = '' then
  begin
    GridKunden.ApplyFilter;
    Exit;
  end;

  // Prüfen, ob ein Komma enthalten ist
  SepPos := Pos(',', Suchbegriff);
  if SepPos > 0 then
  begin
    // Nachname vor dem Komma
    Nachname := Trim(Copy(Suchbegriff, 1, SepPos - 1));
    // Vorname nach dem Komma
    Vorname := Trim(Copy(Suchbegriff, SepPos + 1, Length(Suchbegriff) - SepPos));

    GridKunden.Filter.Add(0, gftStartsWith, Nachname);
    GridKunden.Filter.&Add(1, gftStartsWith, Vorname);
  end
  else
  begin
    // Nur Nachname suchen
    GridKunden.Filter.Add(0, gftStartsWith, Suchbegriff);
  end;

  GridKunden.ApplyFilter;
end;

I found info in

TMS FNC Data Grid for Delphi series part 5: Data filtering

information seems to be missing or I have misunderstood something

Can you provide a sample data for which you want to search?

here is the mistake i made. i wrote &Add for the second parameter and not &And(1,gftStartsWith,SuchbegriffVorname);

Kopierfehler. Richtig ist:
'GridKunden.Filter.Add(0, gftStartsWith, Nachname).&And(1, gftContains, Vorname);'

So it works or do you still have issues?

It works, Thank you.

1 Like