1

The following code allows me to filter a clientdataset by one field:

begin
dmodule.cds.DisableControls;
try
  dmodule.cds.Filtered := False;

  dmodule.cds.FilterOptions := [foCaseInsensitive,foNoPartialCompare];
  dmodule.cds.Filter := 'Field LIKE '+ QuotedStr('%'+ editSearch.Text + '%');

  dmodule.cds.Filtered := True;
finally
  dmodule.cds.EnableControls;
end;

I have added in another line after the first 'cds.Filter' line which I thought would allow me to filter by another field but it doesn't bring back any records.

The line is:

dmodule.cds.Filter := 'Field2 LIKE '+ QuotedStr('%'+ editSearch.Text + '%');

Do I need to do something else to allow multiple filtering?

Thanks,

Sharpie
  • 373
  • 2
  • 15
  • 34

2 Answers2

3

You just combine them with and (you can also use or if need be):

begin
  dmodule.cds.DisableControls;
  try
    dmodule.cds.Filtered := False;

    dmodule.cds.FilterOptions := [foCaseInsensitive,foNoPartialCompare];
    dmodule.cds.Filter := 'Field LIKE '+ QuotedStr('%'+ editSearch.Text + '%') +
                          'AND Field2 LIKE ' + QuotedStr(editSearch2.Text) + '%');


    dmodule.cds.Filtered := True;
  finally
    dmodule.cds.EnableControls;
  end;
Ken White
  • 123,280
  • 14
  • 225
  • 444
3

Your second line basically replaces the filter in the first line. You probably want:

dmodule.cds.Filter := 
         'Field LIKE '+ QuotedStr('%'+ editSearch.Text + '%') + 
     ' OR Field2 LIKE '+ QuotedStr('%'+ editSearch.Text + '%');

Note: I've assumed you want OR because you were surprised about not returning any data. Of course if you require both conditions to be True to return data, then use AND; but you'll still get no records.

Disillusioned
  • 14,635
  • 3
  • 43
  • 77