Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Delphi Grid Filter Assistance

Posted on 2013-01-11
3
622 Views
Last Modified: 2013-01-15
I have a grid that needs a filter that I just can't seem to figure out.

I need it to filter to show records that are either (JobSchedule > 0) OR (PercentComplete < 1) which I have working BUT users sometimes add a criteria to narrow the grid down to a specific JobNumber. When they try to filter to a specific job record and the above filter is applied, it adds the 3rd criteria as an OR when I need it to be AND.  Basically if the user adds any new criteria to filter down to, such as Job#222, I need it to ONLY show Job#222.

Here is the current filter:

       with gvMilling.DataController.Filter do begin
          Root.Clear;
          Root.BoolOperatorKind := fboOR;
          Root.AddItem(gvMillingJobSchedule,foGreaterEqual, '0', 'Department Start Range');
          Root.AddItem(gvMillingMil_Total_PercentComplete, foLess, '1', '100%');
          Active := True;
          end;

Open in new window

0
Comment
Question by:Bianca
3 Comments
 
LVL 32

Expert Comment

by:ewangoya
ID: 38768363
try this way
var
  AItemList: TcxFilterCriteriaItemList;
......
with gvMilling.DataController.Filter do begin
   Root.Clear;
   AItemList := Root.AddItemList(fboOr);
   AItemList.AddItem(gvMillingJobSchedule,foGreaterEqual, '0', 'Department Start Range');
   AItemList.AddItem(gvMillingMil_Total_PercentComplete, foLess, '1', '100%');
   //your new filter, user filter
   Root.AddItem(SelectedCol, foLess, 1000, '1000');
   Active := True;
end;

Open in new window

0
 

Author Comment

by:Bianca
ID: 38768371
That would work IF I knew what that 3rd filter was. It could be JobNumber, JobLocation, Contractor, etc. Is there a way to do this?
0
 
LVL 37

Accepted Solution

by:
Geert Gruwez earned 500 total points
ID: 38769111
have you tried nesting the filter and setting the main level to AND (not or)

- AND ( (JobSchedule > 0) OR (PercentComplete < 1))
- AND (user filter)

the user filter you give a default value which doesn't filter anything, like %
the user can then click the specific filter to narrow down.

they usually don't know that the "filter" word is also a button to add conditions in the filter box.

sample:

procedure TfrmSample.btnSetFilterClick(Sender: TObject);
var fR: TcxDataFilterCriteria;
  fL1, fL2: TcxFilterCriteriaItemList;
begin
  fR := gvMilling.DataController.Filter ;
  fR.Root.Clear;
  fR.Root.BoolOperatorKind := fboAnd;
  fL1 := fR.Root.AddItemList(fboOr);
  fR.AddItem(fL1, gvMillingJobSchedule,foGreaterEqual, '0', 'Department Start Range');
  fR.AddItem(fL1, gvMillingMil_Total_PercentComplete, foLess, '1', '100%');
  fL2 := fR.Root.AddItemList(fBoAnd);
  fR.AddItem(fL2, gvMillingJobNumber, foLike, '%', 'Any');
  fR.AddItem(fL2, gvMillingJobLocation, foLike, '%', 'Any');
  fR.AddItem(fL2, gvMillingContractor, foLike, '%', 'Any');
  fR.Active := true;
end;

Open in new window

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question