How to keep ranges on form datasource when manually add filters?

Thomas Post picture Thomas Post · Jan 23, 2013 · Viewed 11.7k times · Source

I have a strange problem on form: I added a range to filter records in datasource executeQuery() method, this works fine when opening form but if I set manually a filter in the grid header, the range set in ExecuteQuery() method are not applied. My ranges are definied as follow :

this.query.dataSourceNo(1).AddRange(fieldnum(MyTable,MyField)).Value('MyRangeValue');

I use a view as form DataSource, May be it's the problem. Any ideas to always apply ranges and keep it even when manually add filters on grid? Thanks for your help

Answer

Jan B. Kjeldsen picture Jan B. Kjeldsen · Jan 23, 2013

You must apply the filter before the super() in executeQuery().

But I think your problem is you add the filter every time the executeQuery() is run, resulting in an OR in the SQL expression generated.

This is the way to do it:

QueryBuildRange qr = SysQuery::findOrCreateRange(this.query.dataSourceNo(1), fieldnum(MyTable,MyField));
qr.value(queryValue('MyRangeValue'));
qr.status(RangeStatus::Locked); // Or ::Hidden