Set a default value to Column Filter

1- Introduction

Sometimes we need to have filters by default that are loaded when entering the screen, so that we do not have to enter them every time we want to search by the same value.

For example, suppose we have a transaction which has different states loaded into an attribute, states like: "open", "closed", "waiting", etc. As they are fixed values, we can load them into a domain with enumerated values.

Every time we visualize the records, we want to show one of these states by default, to facilitate the user's task. The solution we propose is to load an 'Enum Value' by default in the column filters.

2- Requirements

  • This works only if you have Optimization Number = 8 or higher.

3- Setting values

Open the web panel generated by WorkWithPlus for the "Default List", for example: ProjectWW.  Go to Events tab and look for 'LoadRegFiltersState' Sub.

At start of this subroutine, add the following code (replace all <ATT_NAME> for the attribute name):

If &HTTPRequest.Method = HTTPMethod.Get
  &TF<ATT_NAME>_Sels = new()
  &TF<ATT_NAME>_Sels.Add(Status.Open) //Default Enum Value that you want as default
  WWP_GridStateAddFilterValue(&GridState, !"TF<ATT_NAME>_SEL", true, 0, &TF<ATT_NAME>_Sels.ToJson(), '')
EndIf

It has to look like this:

GeneXus IDE Events editor for a TransactionWW web panel, showing the 'LoadRegFiltersState' subroutine source code that checks HTTPRequest.Method, adds a default enum filter value for <ATT_NAME>_Sels, and calls WWP_GridStateAddFilterValue, followed by the pattern-generated loop over &GridState.FilterValues.

4- Running example:

WorkWithPlus generated Country grid web page reached via breadcrumb Other Options > Developer Menu > Country, showing toolbar buttons Insert, Excel, PDF, Select columns, and CSV, a search box, and Id/Name/Active column headers above a "No records found." message.