Question

I am using a DevExpress TdxMemData in memory TDataSet descendant. While it has Filtered: Boolean and Filter: String properties, it doesn't appear to actually do anything with them automatically, instead relying on the result of the OnFilterRecord event's Accept parameter.

So what I am looking for is a way (maybe it is in TdxMemData or somewhere else in DevExpress's suite of code) to parse the filter text and apply it to the Dataset.

Ideally I would like a way to test an individual row against the filter to see if it matches without filtering it out of the dataset (I want to highlight rows that match the filter).

Example filter string:

((Name = 'Jim') and (Rep > 1000)) or (Rep > 5000)

So there is nested and's and or's. It is actually built by the DevExpress TcxDBFilterControl.

I am really hoping there is something simple I am missing.

Update: I opened a ticket with DevExpress to see if they support any kind of solution. I did find their stock answer that they don't support filtering on TdxMemData.

Was it helpful?

Solution

I know this is not the answer your looking for, but the TdxMemData dataset does not support filter strings. To use filters either code your own OnFilterRecord event or set ProgrammedFilter to true and populate the FilterList with a list of the records which are filtered (at runtime).

One possibility would be to code your own parser to compare the filter string against the current record in the OnFilterRecord event.

OTHER TIPS

You might want to look at replacing the TdxMemData with TkbmMemTable. It's free, works similarly to the DX component, and supports filter strings. Would likely take a lot less time to port over than it would to implement a filter string parser in OnFilterRecord! It'll work with the other DX components without problems.

What you're looking for is not filtering the data, but a matter of displaying it differently if it meets a condition. If you're using a TDBGrid to display the data, look into the DrawColumnCell() event on the TDBGrid:

procedure TForm1.dbgrd1DrawColumnCell(Sender: TObject; const Rect: TRect;
  DataCol: Integer; Column: TColumn; State: TGridDrawState);
var
  DBG: TDBGrid;
begin
  DBG := TDBGrid(Sender);
  // Add any other conditions from your 'filter' here in the next line.
  if (YourData.FieldByName('WHATEVER').AsString = 'Jim') and
     (YourData.FieldByName('REP').AsInteger > 1000) then
    Column.Font.Color := clRed;
  DBG.DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;

Since you're using TdxMemData, you're probably using the DevEx grid, too. It has to have a similar way to do something other than the default drawing; you can use a similar technique there. (I haven't used the DevEx stuff in a few years; current employer doesn't like them, and therefore won't spring for the expense. :-( )

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top