Ticket Q180517
Visible to All Users
Duplicate

We have closed this ticket because another page addresses its subject:

Smart filter row

Filter Row : implement Contains or Like %Value%

created 17 years ago

By default the filter row feature of ExpressQuantumGrid seems to generate filters that match any string starting with a given filter text ie LIKE 'Value%'. Is there a way to change the default filter to 'Like %value%' ?

Show previous comments (3)

    Dimitros,
      Unfortunately that still shows the % signs when the focus is subsequently switched back to the filter row. I tried to create a custom view which overrides the datacontroller to force this behaviour. I need to override the following but neither are marked as virtual. Could you add that as a request for a future version Please.
     procedure TcxGridTableController.AddBeginsWithMask(var AValue: Variant);
     procedure TcxGridTableController.RemoveBeginsWithMask(var AValue: Variant);
      I have updated the source code directly to allow this functionality without having to add event handlers to all my grid views. Here is what I did In case anyone else is interested. Ideally I would like to add an enumerated type to the FilterRow setup that gives the option to use standard behaviour or 'contains' behaviour.
    Regards,
      Will.
    cxGridTableView.pas
    procedure TcxGridTableController.AddBeginsWithMask(var AValue: Variant);
    begin
      if VarIsStr(AValue) and (AValue <> '') and (GetBeginsWithMaskPos(AValue) = 0) then
        AValue := DataController.Filter.PercentWildcard + AValue + DataController.Filter.PercentWildcard;
    end;
    procedure TcxGridTableController.RemoveBeginsWithMask(var AValue: Variant);
    var
      APos: Integer;
      S: string;
    begin
      if VarIsStr(AValue) then
      begin
        if pos(DataController.Filter.PercentWildcard,AValue)=1 then
        begin
          S := AValue;
          delete( S,1,Length(DataController.Filter.PercentWildcard));
          AValue := S;
        end;
        AValue := copy(Avalue,2,length(AValue)) ;//
        APos := GetBeginsWithMaskPos(AValue);
        if APos <> 0 then
        begin
          S := AValue;
          Delete(S, APos, Length(DataController.Filter.PercentWildcard));
          AValue := S;
        end;
      end;
    end;
    function TcxGridFilterRow.GetDisplayText(Index: Integer): string;
    var
      AFilterCriteriaItem: TcxFilterCriteriaItem;
      tmpVar : Variant ;
    begin
      AFilterCriteriaItem := FilterCriteriaItems[Index];
      if AFilterCriteriaItem = nil then
        Result := ''
      else
        if Controller is TcxGridTableController then
        begin
          tmpVar := AFilterCriteriaItem.DisplayValue ;
          TcxGridTableController(Controller).RemoveBeginsWithMask(tmpVar) ;
          Result := VarToStr(tmpVar);
        end else
          Result := AFilterCriteriaItem.DisplayValue ;
    end;

      Turns out I had the first two methods mixed up with some trial code. Here's the working samples.
      procedure TcxGridTableController.AddBeginsWithMask(var AValue: Variant);
      begin
        if VarIsStr(AValue) and (AValue <> '') then
        begin
          if (GetBeginsWithMaskPos(AValue) = 0) then
            AValue := AValue + DataController.Filter.PercentWildcard;
          if pos(DataController.Filter.PercentWildcard,AValue)<>1 then
            AValue := DataController.Filter.PercentWildcard+ AValue ;
        end;
      end;
      procedure TcxGridTableController.RemoveBeginsWithMask(var AValue: Variant);
      var
        APos: Integer;
        S: string;
      begin
        if VarIsStr(AValue) then
        begin
          if pos(DataController.Filter.PercentWildcard,AValue)=1 then
          begin
            S := AValue;
            delete( S,1,Length(DataController.Filter.PercentWildcard));
            AValue := S;
          end;
          APos := GetBeginsWithMaskPos(AValue);
          if APos <> 0 then
          begin
            S := AValue;
            Delete(S, APos, Length(DataController.Filter.PercentWildcard));
            AValue := S;
          end;
        end;
      end;

      DevExpress Support Team 17 years ago

        Hi Chris,
        Thank you for sharing your code with us. I'm glad to hear about your progress.
        As a voting system, we count the number of trackers for a certain report. For more details, please read Julian's blog at http://community.devexpress.com/blogs/ctodx/archive/2008/06/13/bug-reporting-and-tracking.aspx.
        So, I recommend that you start tracking AS17729 ("FilterRow - LIKE filters - Make it possible to automatically add % to a filter condition when the FilterRow.ApplyChanges property is set to fracOnCellExit") and AS17730 ("FilterRow - Ability to customize the filter condition applied by the filter row and filter row text") reports to take into account your vote.
        Thanks,
        Dimitros

        Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

        Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.