It is possible to allow end users of applications generated by GeneXus to select values and descriptions from a list of suggestions as they type. Even though these suggestions are loaded from attributes by default, you can use a Data Provider object to provide the suggestions instead.
The Data Provider object allows making a "Suggest" with data obtained from a service, and this component can rely on external sources. This feature is especially valuable in cases where the Panel object or Web Panel object do not have direct access to data through attributes, thus enriching the user experience by offering broader and more relevant selection options.
To achieve this, configure the following on objects for web applications or objects for native mobile applications:
- Set the appropriate properties
- Configure the Data Provider
You have two configuration alternatives for the attribute/variable for which you want to provide this functionality:
When the Data Source From property is set to Data Provider, the following properties are offered:
Make sure that the Data Provider object contains a Parm rule (defined in the rules section) that declares:
- The parameters corresponding to those specified in the Parameters property in the same order as they were defined in that property.
- In addition, the following last three parameters, in the following order:
- &FilterOperator (string): Contains either "BeginsWith" or "Contains" values, depending on what was specified in the Filter Operator property of the control.
- &Count (numeric): Contains the maximum number of records to be searched for.
- &SearchText (string): Represents the text by which the user is trying to filter.
Since the Data Provider supplies the data used in the "Suggest" to propose values to the end user, it is essential that this data be returned in the appropriate format:
- Input Values and Input Descriptions: The data returned must be a list of input values (Input Values) or pairs of input values and descriptions (Input Descriptions).
- Type Compatibility: Input Values must match the type of the variable associated with the control, which ensures that the data is consistent and usable. On the other hand, Input Descriptions must be of string type, such as Character or Varchar.
- Parameter and Field Names: Although the specific names of the parameters or fields returned are not crucial, it is critical that the data types are correct. This means that the Data Provider can use different names for the values and descriptions, as long as the data types conform to the above.
Suppose you want to do the same as shown in HowTo: Use the Data Source From property. However, in this case, you want to use Edit with Suggest.
To accomplish this, create the SDT and define the Data Provider as follows:
Parm(CompanyId, &FilterOperator, &Count, &SearchText);
ContactsSDTItem [Count = &Count]
Where ContactName like &SearchText when &FilterOperator = !'BeginsWith'
Where ContactName like !'%' + &SearchText when &FilterOperator = !'Contains'
ContactId = ContactId
ContactName = ContactName
This functionality is available since GeneXus 18 Upgrade 5.