How is best to go about adding to a filter dynamically? I have seen the documentation regarding the chaining of filters but I haven't been able to add dynamically another condition to a column that already has a condition applied to it.
How are gftNotEqual / gftNotContains supposed to work? I have added it as a filter in the form of .Filter.Add(0, gftNotEqual, val)
and .Filter.Add(0, gftNotContains, val)
but all it does is blank the data. I was presuming that the intention of these was to filter out whatever is passed as val?
Unfortunately, this hasn't fixed my issues. In the example you've given, you've added the conditions dynamically at the same time; I want to add the second condition after the first, i.e.
I have the dynamic filter chaining working now. Thank you for the example!
However, I still can't get the gftNotEqual/gftNotContains to work.
I have set up a new project and added a TMSFNCDataGrid and two buttons to it. I have added the following routines:
procedure TForm1.WebFormShow(Sender: TObject);
begin
TMSFNCDataGrid1.LoadSampleData;
end;
procedure TForm1.WebButton1Click(Sender: TObject);
begin
TMSFNCDataGrid1.ClearFilter;
TMSFNCDataGrid1.Filter.Add(1, gftNotContains, 'a');
TMSFNCDataGrid1.ApplyFilter;
end;
procedure TForm1.WebButton2Click(Sender: TObject);
begin
TMSFNCDataGrid1.ClearFilter;
TMSFNCDataGrid1.Filter.Add(1, gftNotEqual, 'Marie?Terzi');
TMSFNCDataGrid1.ApplyFilter;
end;
Hi after further testing, we noticed an issue in processing the filter in TMS WEB core. We didn't notice at first you were targeting TMS WEB core. A fix can be expected in the upcoming release, aimed for this week.
You can add an remove filters, it's a collection. The first one does not need an operation, but all the others need an AND or OR operation. Note that with each filter being added or removed, you need to clear and reapply filters. Unfortunately there is no built-in way to search for a specific filter, you'll have to do this yourself.
function TForm22.FilterByID(AID: string): TTMSFNCDataGridDataFilterData;
var
I: Integer;
begin
Result := nil;
for I := 0 to TMSFNCDataGrid1.Filter.Count - 1 do
begin
if TMSFNCDataGrid1.Filter.Items[I].DataString = AID then
begin
Result := TMSFNCDataGrid1.Filter.Items[I];
Break;
end;
end;
end;
If you want to add a filter, uniquely identify it with the DataString property.
var
f: TTMSFNCDataGridDataFilterData;
begin
TMSFNCDataGrid1.ClearFilter;
f := FilterByID('MyFirstFilter');
if Assigned(f) then
TMSFNCDataGrid1.Filter.Delete(f.Index);
TMSFNCDataGrid1.ApplyFilter;
end;
In this scenario, MyFirstFilter will be cleared after the ClearFilter() and MySecondFilter can't be chained because we've deleted the other filter?
And in the remove an existing filter example, doesn't calling ClearFilter() simply clear all the filters anyway, so calling ApplyFilter() won't do anything because we've cleared all the filters?