Problems with data formatter

:+1::clapper::movie_camera:

1 Like

Hello @dvan_zelst,
Indeed there is a small issue using the data formatter in the table generator, which we are going to fix.

Currently you could just generate your table, then select the field showing the division_active and use the formatter in the inner-text property:

So your expression should just be:

division_active == 1 ? 'enabled' : 'disabled'

what this check does is:

IF division_active == 1
show enabled
otherwise show disabled.

Hello Teodor,
Thanks for your feedback. As you can see from the previous post we found several ways to make it work. I could even get it to work using the formatter UI itself. For now i just wanted to report the issues i came across thinking doing it the correct way.

  1. I got a variable error message when trying to format the field directly in the BS form generator.
  2. My database query is showing a number type field for my Tiny INT DB field, but in the table / formatter UI it is indicated as a strings field
  3. When trying to use the formatter to replace the number as a number type field into a string type text with a manipulator replace function, the results shows nothing. Maybe it is caused by point 2, don’t know. To make it work i first need to convert the number to a string and then use the replace function.
  4. when adding a string conversion in the formatter, this function disappears from the stack when re-opening the formatter.

As discussed i’m just learning Wappler with the training videos made by ‘psweb’ and came across these things. I’m not working on a project, just learning :slight_smile:

I think the number field should be seen as a number field in the table / formatter but besides that i do not understand why the replace function does not work when searching for a number type to replace with text. It should work that way right?

Thanks for your support and keep up the good work with Wappler!

Hello,

  1. Will be fixed

I will check 2,3,4 but the problems described there seem to be caused by the same things.

Anyway in your case the code i pasted is the simplest and most effective way of doing what you need - no need of using replace, as replace is used more for strings than for numbers.

Thanks Teodor!
Just wanted to show what i did for you to determine if there might be a small bug.
I will try to replace the code you gave me.
Just tried to get it working using the Formatter UI instead of adding code directly.

The code can be added through the formatter as well :slight_smile:

May i ask how to get this code using the formatter? Which actions to choose from there instead of using replace?

You can use the “Operator” filter:
Screenshot_85

to build the expression you need:

Still - quite faster writing it in the field.

1 Like

Thanks, did not know that one obviously. :slight_smile:

Just to know, should replace also work to replace a number to text in this case or is it completely wrong way of doing it and therefor not working as expected? Just trying to understand, so many functions and features LOL!

Replace filter is for strings, not for numbers. You can convert the number to string first and then use replace.
However i see you reported a problem with this workflow and we are going to check this.

The problem doing that way is when i leave the search for as a number type. It will then not show anything in the output. It makes sense if it is only for strings which i did not know because it sets the type field to number automatically when adding a number in the search for field.

However if i first change the number to a string and then search for the number as a string type it works as expected. The only bug here is that the convert to string action disappears when re-opening the fomatter UI.

Yes i got that, you already explained these issues in your previous post.
We are going to check these and i will let you know when we fix them.

If this is fixed, do you think this will cause problems retrospectively, eg to code like this:
offset={{$index + query.offset.toNumber()}}
?

I’ve found it necessary to convert variables already defined as numbers, to numbers, in order for them to work in situation like the above - probably in quite a few cases. I wasn’t sure if this is was a bug or not. I’ve been meaning to ask about it.

Perhaps a bit late, but there is also a Then formatter, in the formatters just tell that division_active is a boolean and then add the Then formatter under Conditional, so the expression gets then division_active.then("enabled", "disabled").

1 Like

Thanks i will give them all a try. I’m sure there are multiple ways of getting this done inside the formatter. At first glance the replace looked most obvious to me but was not aware it is for strings only. I’m not that experienced coding wise but it all makes sense. I will play a bit more with this formatter just to get more familiar with it. :slight_smile:

Hi Patrick,
I have tried your expression but it does not work unfortunately. Was worth trying.
Teodor expression does work and i also found some other ways to make it work. It is just that you have to know what the value is, string or number and which functions apply to strings or numbers i guess. Will play more with this formatter to see what kind of results i will get to learn from it.
Thanks though and no worry as it is working already and just for learning purpose!.

Good that you have found some working solutions, I see that mine indeed does not work, it need to be a real boolean for the Then formatter, changing the expression to (division_active == 1).then("enabled", "disabled") would work.

1 Like

BRILLIANT @Teodor, always wondered how to get this working through the formatter, thank you so much for showing it that way, really helps me understand.

2 Likes

Yes brilliant!
Though if you know how the code should be it looks easy but if you have no idea using the operation function in the formatter does require some understanding as well. It would never have crossed my mind to use this function to do this. Still trying to learn and understand this operation function and all other features. :slight_smile:

Just updated to the latest version v1.3.0. but when adding a convert to string in the formatter it still disappears from the stack when reopening the formatter. I gues this is not yet fixed.