Sort a custom content column in a datagrid

0
Hello, I have an entity displayed in a grid and I have a custom content column where I display information based on a visibility condition. So I have 2 name attributes in my entitiy, firstName, secondNameOne attribute is empty and another one is not empty. I use the visibility condition to simply display the one that's not empty. The problem is that I cannot sort the grid based on this column because it's not poiting to a specific attribute.
asked
2 answers
0

Hello Fob,

This is a very interesting problem but I think we can't fix it easily by simply focusing on the grid & xpath or DS microflow

I think you should use OQL (view entities) to achieve this. There's a cool function named COALESCE

https://docs.mendix.com/refguide/oql-expression-syntax/#coalesce-expression

This may achieve what you want because you can it returns the value of the first expression that is not NULL. Can be used with columns.

Check the examples here ->

https://docs.mendix.com/refguide/oql-expression-syntax/#coalesce-expression-examples.

The advantage of this one is that you can extend the OQL query to sort based on it. Should be possible somehow

Hope this helps!

answered
0

hi,


This is expected behavior.

In Mendix, sorting always happens on the datasource, not on what is rendered in the UI. A custom content column with visibility conditions doesn’t represent a single attribute, so the grid has nothing concrete to sort on.

What we usually do in this situation is introduce a single “display” attribute and sort on that.

For example:

  • Add a DisplayName attribute to the entity
  • Populate it whenever the object is created/updated:
    • If firstName is not empty → use that
    • Else → use secondName

Then:

  • Bind the column to DisplayName
  • Enable sorting on that column

If you’re using a microflow datasource, you can also calculate DisplayName there and return the list already sorted.

There’s no supported way to sort based on visibility logic or custom content alone. The sort key must always be a real attribute in the datasource.


answered