How does the Greater search field in a grid work for string attributes?

1
I have to filter on certain attributes in a data grid (regular one, not grid 2. I cannot use that one in my scenario).  One attribute is a string value (that contains numbers).  I see that it's possible to use a comparison search with the options 'Greater' or 'Smaller'. But I fail to understand how this applies to string values.  I checked the Mendix documentation, but I couldn't find a clear answer.   If anyone could enlighten me, please do :) 
asked
1 answers
0

Hi Rolf

 

This is a good question and something that often causes confusion

 

When you use the Greater or Smaller search options in a Mendix data grid for a string attribute the comparison is done lexicographically rather than numerically This means that the system compares the values based on their character sequence similar to how words are ordered in a dictionary

 

For example, if your string attribute contains values like 10 2 and 100 and you search for values greater than 10 you might expect 100 to match However in a string comparison 100 is actually considered less than 2 because the comparison starts from the first character and goes left to right

 

This behavior is expected for string attributes even if they contain numbers

 

If your intention is to compare numeric values, it is best to store the data in a numeric type such as Integer or Decimal instead of String This will ensure that the Greater and Smaller filters behave as expected and compare actual numerical values

 

If changing the attribute type is not possible you would need to handle the comparison logic using a microflow where you can convert the string to a number and then apply the appropriate logic manually

 

Hope this clears things up!

 

Please mark this answer as accepted if you satisfied with this explaination.

answered