How can I format boolean type for data source type JSON?

Answered
Rodrigo Arantes asked on July 12, 2021

Here is a data source config example:

datasource: {
type: "json",
data: [{
firstName: "User",
lastName: "Peixoto",
salary: 90000,
birthDate: "2020-12-31",
terminated: false,
}]
}

Is there a data type boolean or formatting setting for it? Couldn't find it in mapping object.

6 answers

Public
Mykhailo Halaida Mykhailo Halaida Flexmonster July 13, 2021

Hi Rodrigo,
 
Thank you for posting your question.
 
Flexmonster does not provide a separate field type for boolean values. Instead, by default, they are recognized as regular string fields.
 
Please let us know if this helps.
 
Best regards,
Mykhailo

Public
Rodrigo Arantes July 13, 2021

Hi Mykhailo,
What is the best approach to instead of displaying "true" or "false" we display a friendly format like "Yes" or "No"

Thanks

Public
Mykhailo Halaida Mykhailo Halaida Flexmonster July 14, 2021

Rodrigo,
 
Thank you for your response.
 
The preferable approach in this situation is to modify the data source so that it already contains the "Yes"/"No"-value field you want to display.
 
However, it becomes easier if you're using inline JSON data as your data source: you can set up a data preprocessor on the client-side that will add the necessary field to the data before feeding it to the pivot table. This way, the original data stays unchanged, but it is also displayed as necessary in your Flexmonster instance.
 
Here's a quick example demonstrating this approach: https://jsfiddle.net/flexmonster/ru6fz1vj/.
 
Hope this helps!
 
Regards,
Mykhailo

Public
Rodrigo Arantes July 14, 2021

Hi Mykhailo,
That's what I was trying to avoid. Wanted to see if there was something built-in related to data formatting.
Thanks for quick response 

Public
Mykhailo Halaida Mykhailo Halaida Flexmonster July 15, 2021

Hi Rodrigo,
 
I just realized there's a much simpler solution involving the customizeCell() API call.
 
It does not require you to modify the input data – instead, you simply rewrite the cell labels in the grid without affecting the underlying data.
 
Here's a sample for demonstration: https://jsfiddle.net/flexmonster/w6uvf3Lm/.
 
Does this solution suit you better?
 
Regards,
Mykhailo

Public
Rodrigo Arantes July 15, 2021

Hi Mykhailo,
That's the one I went for. 

Thanks a lot for the follow up ?
 

Please login or Register to Submit Answer