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%' ?
We have closed this ticket because another page addresses its subject:
Smart filter row
Hi Chris,
This problem has been already discussed in our Support Center. Please review CQ61097 ("Smart filter row") and Q101164 ("how to chagne the default behavior for the "begins with" filter") reports.
I've attached a small example. Please review it and inform me whether it meets your requirements.
Thanks,
Dimitros
Dimitros,
Thankyou for the sample. It does pretty much what I need but does still have a problem. When the filter row loses focus the filter row value is changed to include the % signs. I don't fancy the idea of explaining to users what the % signs are for. I would prefer to see some way of choosing whether a "starting with" or "contains" query is used by default without changing the user entered text.
From reading the other reports I gather that this is not possible at the moment. Is there a way to vote for a new feature to be implemented. Better still, is there a timescale on when a feature like this might be added?
Regards,
Will.
Hi,
Sorry, but we don't plan to implement this behavior in the near future. 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 learn about our progress over this item.
I've attached a small sample which illustrates how to hide the % signs when the FilterRow loses focus. I hope it will help you achieve the desired effect.
If you need any further assistance on this subject, please feel free to reactivate this ticket.
Thanks,
Dimitros
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;
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