Solved

Delphi Grid Filter Assistance

Posted on 2013-01-11
3
603 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 36

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

707 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now