Jump to content

Clear Column Filters via code


edbuescher

Recommended Posts

I have a filtered TUniDBGrid with multiple columns and with the option dgFilterClearButton set.

How do I simulate either
1) Clicking the Filter Clear Button or
2) Clicking the 'X' on the filtered Columns to disable those column filters

I can clear the underlying filter on the dataset, but that doesn't clear the various Column filtering criteria

Thanks

Link to comment
Share on other sites

54 minutos atrás, Edbuescher disse:

Tenho um TUniDBGrid filtrado com várias colunas e com a opção dgFilterClearButton definido.

Como simular
1) Clicar no botão de limpar filtro ou
2) Clicar no 'X' nas colunas filtradas para desativar esses filtros de coluna

Eu posso limpar o filtro subjacente no conjunto de dados, mas isso não limpa os vários critérios de filtragem de coluna

Obrigado

for var i : Integer := 0 to Self.FGrid.Columns.Count - 1 do
      begin
        if (Self.FGrid.Columns[i].Filtering.Enabled) and (Self.FGrid.Columns[i].Filtering.Editor <> nil) then
        begin
          lUpdate := True;
          if Self.FGrid.Columns[i].Filtering.Editor is TUniEdit then
            TUniEdit(Self.FGrid.Columns[i].Filtering.Editor).Clear
          else
          if Self.FGrid.Columns[i].Filtering.Editor is TUniCheckComboBox then
            TUniCheckComboBox(Self.FGrid.Columns[i].Filtering.Editor).ClearSelection
          else
          if Self.FGrid.Columns[i].Filtering.Editor is TUniDateTimePicker then
            TUniDateTimePicker(Self.FGrid.Columns[i].Filtering.Editor).Text := '';
        end;
      end;

 

Link to comment
Share on other sites

Obrigado,

Thank you for your sample code, however it doesn't actually clear the filters.

Example: if I have a grid with 20 rows and one of the columns displays Dates, then I use a UniDateTimePicker column editor to filter the column to a specific date, such as 8/10/2022, the grid will respond and only show rows with that date. Then if I run your code and set the UniDBGrid.Filter:='', I will be back to showing all 20 rows. At this point if I use the drop down menu for the UniDateTimePicker and choose 8/10/2022 again, nothing happens, as the Grid still thinks that's the selected date being used. If I select a different date, then the filtering works on the new date. I've tried this on the other types of column editors (UniComboBox, etc) with the same effect.

If there is a way to click the Grid's "FilterClearButton" on the left side of the columns, that would solve the problem.

I'm open to suggestions.

Thanks again,

Eric

 

Link to comment
Share on other sites

Sherzod,

I am doing this on the server side via Delphi code.  I must be missing something.

In Delphi, how do I click the Grid's FilterClearButton on the left side of the columns, or how do I click on the 'x' in a particular Column heading to clear the filtering for that column?

Eric

Link to comment
Share on other sites

Don't know how I missed that, but it still doesn't clear the underlying filter. After executing the Grid.ClearFilters, the grid does display all the rows as though the filters were all cleared, but if you select the last thing you filtered on, the Grid doesn't respond because it still "knows" the last thing you filtered on, even After the ClearFilters command.

Do I need to write a sample program to demonstrate?

Thanks again,
Eric

Link to comment
Share on other sites

2 hours ago, edbuescher said:

Não sei como eu perdi isso, mas ainda não limpa o filtro subjacente. Depois de executar o Grid.ClearFilters, a grade exibe todas as linhas como se os filtros estivessem todos limpos, mas se você selecionar a última coisa que filtrou, a grade não responderá porque ainda "sabe" a última coisa que você filtrou ligado, mesmo após o comando ClearFilters.

Preciso escrever um programa de exemplo para demonstrar?

Obrigado mais uma vez,
Érico

here it helped me, after cleaning it, I send it to update the query

Link to comment
Share on other sites

12 hours ago, edbuescher said:

After executing the Grid.ClearFilters...

Also try this code:

procedure TMainForm.UniButton2Click(Sender: TObject);
begin
  with UniDBGrid1 do
    if (dgFilterClearButton in Options) then
      JSInterface.JSCallGlobal(Self.Name + '.' + Name + 'ClearButton.click', [])

end;

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...