DIY Search In Your Mendix Apps

While there are a lot of easy ways to include searching with your Mendix widgets, you may want to consider building your own search functionality to have total control over the UI/UX and to take advantage of some of the fantastic Marketplace widgets. Creating custom search functionality is simple and can result in engaging reusable components for your application.

Consider the following domain model:

Example domain model for an ordering process

In this example I am creating a custom search feature for an Order Overview page. I want to implement a custom search because I want full control over the way the search is presented, so this method allows me to lay out and style my search fields in any way I choose. My page starts with a datasource microflow to bring in Search and nested within the Search dataview is a datagrid of Orders to show the results of my search. I have laid out my search fields and added a couple of helpful widgets to handle my reference set associations.

Any layout is possible, and Marketplace widgets can make for a better UX overall

When the Search button is clicked, a microflow is called to evaluate my current search criteria and return a list of Orders. In essence, this microflow performs a retrieval of Order from the database with XPath. To make it easier to understand for my less experienced colleagues, I have created a couple of variables to help make the XPath easier to read and understand.

Microflow to retrieve Order results based on Search attributes. This can be triggered by a button for manual searching or on-change of the Search attributes for real-time filtering

Each variable helps to pre-evaluate the associations that can be made from my Search entity and check to see if those associations are empty or not. When empty, my variable will be True, and when at least one record is selected over association it will be False. This will help me later when I am writing my XPath constraint.

The Boolean variables check for the lack of selected records over association

When writing my XPath constraints, I make use of the Boolean variables with an OR so that if the variable is True if will skip to the next constraint, OR if false then it will constrain my Order results appropriately. While the variables are not necessary because you could simply check for the empty associations in the constraint, they do make it easier to read and explain.

XPath example showing the use of the Boolean variables

The resulting OrderList is returned and I use a Change Object action so that I can set the Order_Results association to the returned OrderList. Adding the Refresh In Client option ensures that my datagrid updates with the new list of Order results.

The application now has a working custom search implementation that looks great and is very easy to extend with additional attributes or associations as the application develops further.

This blog was originally published by Kyle Kunzer on October 2nd 2023 here: 

Living On The Edge: Mendix On An Embedded Device
Image of Kyle Kunzer
Kyle Kunzer

I was recently asked about Mendix in the context of Edge computing; that is where an application...

Top 7 Reasons for Kinetech PM
Image of kinetech

For construction professionals, the process of constructing a building cannot change. It will...

SaaS: Multi-tenant Vs. Single-tenant
Image of kinetech

As companies continue to migrate legacy software applications to the cloud it is important for...