Hi Siddharth,
To efficiently implement server-side pagination in Mendix when using XPath constraints with associated entities, follow these best practices:
Use a Non-Persistable Helper Entity:
Create a non-persistable entity (e.g. SearchParameters
) to store filter values like page size, offset, and association filters. Pass this to a microflow or nanoflow for querying.
Use [id = '[%CurrentObject%]']
for Association Filtering:When filtering by association in XPath, use an efficient format like:
[YourModule.AssociationName = '[%CurrentObject%]']
This avoids joins and improves performance.
Use limit
and offset
:Add limit
and offset
parameters in your microflow using the Retrieve activity with XPath. This allows Mendix to handle pagination at the database level:
Offset = (PageNumber - 1) × PageSize
Limit = PageSize
Example XPath for Pagination:
[YourModule.AssociationName = '[%CurrentObject%]']
Set the Range option in the Retrieve activity to Custom, then provide the offset and limit.
Avoid retrieving large lists and paginating client-side, especially for mobile or web apps with performance-sensitive UIs.
Bonus Tip:If you also need sorting, consider retrieving via OQL (in newer Mendix versions) or custom Java actions, but only if XPath becomes a bottleneck.
Hope it helps!!