"Pre" filtering a query

If you have questions or if you want to share your opinion about Aware IM post your message on this forum
Post Reply
Posts: 2
Joined: Thu Feb 13, 2020 9:48 pm

"Pre" filtering a query

Post by fazman »

I'm not really sure where to post this or if it is of use/ relevant - so apologies if this is in the wrong place
I searched the forum earlier because I was wanting to find a way to do this - but not finding anything, I read through the guides and kendo docs and came up with a solution.

The problem:
In some instances, I need to "pre" filter a query - for example, I want to show only active records when a query is first displayed - but I want the user to be able to override this if they need to - so a where clause is out, and I really don't want to create a separate query for active/inactive etc

The solution:
This is a render script to be used on the query:

var grid = widget;
var ds=grid.dataSource;
ds.filter( {
logic: "and",
filters: [
{field: "fieldName", operator: "operator - eg eq/neq ... ", value: "value" },
{field: "IsActive", operator: "eq", value: "Yes" }

Hopefully I've given enough detail to help you understand what I'm saying

One final note - I found that the abbreviated versions of the operators - ie eq as opposed to equals, seem to work better, although there was a bit of trial and error getting all the format right so I should probably test that again.

Hope someone finds it useful
Posts: 2197
Joined: Mon Jul 02, 2012 12:24 am
Location: Ulaanbaatar, Mongolia

Re: "Pre" filtering a query

Post by eagles9999 »

I would do it something like this.....

In the RegularUser BO add an Attribute called MyQueryFilter PLAIN TEXT with Default Value 'ACTIVE' and Options of 'ACTIVE' and 'ALL'

The Query is called 'MyAwesomeQuery' will look like this...

FIND MyData WHERE((MyData.Status='Active' AND LoggedInRegularUser.MyQueryFilter='ACTIVE') OR LoggedInRegularUser.MyQueryFilter='ALL')

Create a Process called ToggleQueryFilter
IF LoggedInRegularUser.MyQueryFilter='ACTIVE' THEN

Create a Panel Operation Button on Top Panel of the Query called, say, Toggle Filter which calls this Process

To Display the Query .... Create a Process DISPLAYMyAwesomeQuery
DISPLAY 'MyAwesomeQuery'

Then add tom the refresh rules of the Query...... MyData and the Process ToggleQueryFilter

Here is a litte demo of the above....
(39.24 KiB) Downloaded 175 times
AwareIM 6.0, 8.4, 8.5b (build 2806) MS SQL Server 2012 / MariaDB, Windows 10, Ubuntu Linux, Theme: Default, Browser: Chrome
Upcloud, AWS
Posts: 1828
Joined: Tue Jan 13, 2015 10:58 am
Location: Tampa, FL

Re: "Pre" filtering a query

Post by Jaymer »

this is DAMN Useful !!!! Thanks for knocking this out.
And its been needed for a long time.
Took me 2 minutes and worked first time.

Its a pain to have to make redundant queries - 1 for All Customers, and another for Only Active -- just to save the users from having to constantly enter a filter. Filtering is easy - but users get tired of it if they have to constantly enter the same stuff many times a day (since we don't have a elegant way for saved user-filters).

And I've used Mark's method plenty of times - but thats still a hassle to get done with temp fields needed and Processes to toggle, etc.
(Mark's method will be easier in the next version because you will have a in-memory set of temp fields available - so these will NOT have to be constantly written to LIRU)

I only needed 1 field, so haven't played with this much.

Code: Select all

var grid = widget;
var ds=grid.dataSource;
ds.filter( {
logic: "and",
filters: [
{field: "ActiveYN", operator: "eq", value: "Y" }
--> JaymerTip pre-filter a Query with clearable filter values
Click Here to see a collection of my tips & hacks on this forum? Or search for "JaymerTip" in the search bar at the top.

Aware Programming & Consulting - Tampa FL
Post Reply