DataSet filters and title menu filters

Comments

3 comments

  • Roy Woll

    You can have the filtering not use the OnFilterRecord and instead use the Filter Property of the dataset to avoid any conflicts. To do this, you can initialize your grid as follows.

       // By calling FormGridFilterTypesNeeded it will initialize this data structure so it would not be nil afterwards.
      wwdbgrid3.FormGridFilterTypesNeeded;

      // Use FilterProp instead of callback filter
      TwwFilterDialog(wwDBGrid3.FormGridFilterTypes.FilterDialog).FilterPropertyOptions.DatasetFilterType:= fdUseFilterProp;
    1
    Comment actions Permalink
  • Jon Robertson

    Thank you. I'll try this when I have a chance, hopefully sometime today.

    0
    Comment actions Permalink
  • Jon Robertson

    I'm posting my current approach in case someone else wants to do something similar.

    Using your suggestion, my first approach was to manually modify the dataset's Filter property, adding or removing my filter to the one set by TwwFormGridFilterTypes. Although that worked, I didn't like working around the grid's filtering implementation.

    I was able to accomplish what I want with the procedure below, which is called from the OnClick event that toggles my filter and the grid's OnAfterMenuFilter event handler. In my scenario, MyField is not shown in the grid and the user cannot add it via Add Column. If the user could, the procedure below would have to accommodate any filtering that the user set on the field via the title menu filter.

    procedure TForm1.UpdateVendorFilter(AFilterAction: TwwGridFilterAction);
    const
      MYFIELD = 'MyField';
      
    begin
    // I pass None for AFilterAction when called from the "UseMyFilter" checkbox OnClick event.
      if not (AFilterAction in [None, ClearAll]) then
        Exit;

      if cbxNoSend1099Claims.Checked then begin
        var item := TwwFilterDialog(dbGridVendor.FormGridFilterTypes.FilterDialog).AddFieldInfo();
        item.fieldName    := MYFIELD;
        item.DisplayLabel := item.fieldName;
        item.MatchType    := fdMatchExact;
        item.filterValue  := '0';
      end
      else begin
        for var iLoop := 0 to TwwFilterDialog(dbGridVendor.FormGridFilterTypes.FilterDialog).FieldInfo.Count - 1 do begin
          var itm := TwwFilterDialog(dbGridVendor.FormGridFilterTypes.FilterDialog).FieldInfo[iLoop];
          if TwwFieldInfo(itm).FieldName = MYFIELD then begin
            TwwFilterDialog(dbGridVendor.FormGridFilterTypes.FilterDialog).FieldInfo.Delete(iLoop);
            TwwFieldInfo(itm).Free();
            break;
          end;
        end;
      end;

      TwwFilterDialog(dbGridVendor.FormGridFilterTypes.FilterDialog).ApplyFilter();
    end;

    In addition to your code above, I had to set the FilterDialog's DataSource property, for the scenario where a user clicks my filter checkbox before or without filtering via the grid's title buttons.

      TwwFilterDialog(dbGridVendor.FormGridFilterTypes.FilterDialog).DataSource := dtsrcBlah;

     

     

    0
    Comment actions Permalink

Please sign in to leave a comment.

Powered by Zendesk