How to add a filter on column in data grid 2 for a calculated attribute ?

0
in DG2 i want to add a search filter on column and the column contains calculated attribute
asked
3 answers
0

In DataGrid 2, filtering only works on persisted attributes at database level.


If your column uses a calculated attribute, the filter will not work because calculated attributes are evaluated at runtime, not stored in the database.


To solve this, you have two options:


First option (recommended):

Replace the calculated attribute with a persisted attribute and update its value using a microflow (for example on create/update events). This allows the database to filter correctly.


Second option:

Change the DataGrid 2 data source to a microflow and implement the filtering logic manually inside that microflow.


Best practice in enterprise apps is to avoid filtering on calculated attributes and use persisted attributes instead.


If this resolves the issue, please close the topic.


answered
0

Hi Tushar Rajput


Not supported. Data Grid 2 filters & sorting only work on real database attributes (persisted fields). Calculated attributes aren’t filterable/sortable because they’re resolved at runtime and not part of the DB query.

Workable patterns:

  1. Persist the value: Add a normal attribute (e.g., CalcValueStored) and keep it in sync with events (Before commit, After commit, microflow on change, or scheduled job). Bind DG2 to this stored attr → native filters & sorting just work.
  2. Helper filter + datasource microflow: Put filter controls (Text box, Drop‑downs) bound to a helper entity. Use a datasource microflow for DG2 that applies the constraints (XPath/logic) using the helper values and recalculates in the MF if needed. (You lose DG2 built‑in filters for that column; you own the filter UI.)
  3. DB view / OQL: Move the calc into the database (DB view or OQL returning a non‑persistable entity). Show it in DG2. Built‑in filters still won’t bind to non‑persistable fields—so pair with custom filter controls (pattern #2).
  4. Denormalize simple calcs: If deterministic from other fields, compute on write and index the stored column for fast search/sort.

Let me know if this helps


answered
0

Hi,


You cannot directly apply a column filter in Data Grid 2 on a calculated attribute.

This is expected behavior.

Why?

Data Grid 2 filtering works at the database query (XPath/OQL) level.

A calculated attribute is evaluated in memory after retrieval, not stored in the database.

Since the value does not physically exist in the database:

  • It cannot be used in XPath constraints
  • It cannot be indexed
  • It cannot be filtered server-side
  • Data Grid 2 cannot generate a query filter for it

That is why the filter option does not work.


Data Grid 2 filters only work on persisted database attributes.

Calculated attributes are evaluated at runtime and cannot be used in query filters.

If filtering is required, convert the value into a stored attribute or use a microflow data source.

This is by design in Mendix and aligns with how server-side filtering operates.

Solutions

Option 1 – Convert to Stored Attribute

If filtering is required:

  1. Change the calculated attribute to a normal persisted attribute
  2. Populate it:
    • In a Before Commit event
    • Or via scheduled update
    • Or when related data changes

Now the value exists in the database, and Data Grid 2 can filter it normally.

This is the cleanest and most scalable solution.

Option 2 – Use Microflow Data Source

If you must keep it calculated:

  1. Change Data Grid 2 data source to Microflow
  2. Pass filter values as parameters
  3. Perform filtering logic inside the microflow
  4. Return filtered list

This works, but:

  • Pagination must be handled carefully
  • Performance may degrade for large datasets

Use only if dataset is small or logic is complex.

Option 3 – Duplicate as Helper Attribute

Keep the calculated attribute for display.

Create a second stored attribute purely for filtering.

Synchronize it whenever source values change.

This gives best performance and flexibility.

What Will NOT Work

  • Trying to apply filter directly on calculated attribute
  • Using dynamic expressions in filter
  • Forcing client-side filtering (DG2 does not support full client-side filtering)


answered