Need a special offer?Find out if your project fits.
+

Add decimalPlaces to some columns

Answered
Denis asked on December 1, 2020

Hi all! In my report I need to add floating point numbers with two numbers after dot, like 137.00 or 125.21. I found how I can do it for all columns

formats: [
{
thousandsSeparator: ',',
decimalSeparator: '.',
decimalPlaces: 2,
maxDecimalPlaces: 2,
},
],

But I need to add these props not to all of the table columns, I need to add on some columns for example (screen)
I also tried this code

formats: [
{
thousandsSeparator: ',',
decimalSeparator: '.',
},
{
name: 'total',
decimalPlaces: 2,
maxDecimalPlaces: 2,
},
],
slice: {
measures: [
{
uniqueName: 'ot',
format: 'total',
},
],
},

But it show only 1 column 'Total'. Can i somehow show all columns but 2 columns with format 'XX.00' without listing all columns in slice -> measures?
 

4 answers

Public
Tanya Gryshko Tanya Gryshko Flexmonster December 2, 2020

Hello, Denis,
 
Thank you for posting to our forum.
 
First of all, we would like to confirm, that you can set the format XX.00 for all columns with the following code:

formats: [
{
thousandsSeparator: ',',
decimalSeparator: '.',
decimalPlaces: 2,
maxDecimalPlaces: 2
},
],

Then, if you want to override this format for columns Rate Group and Carrier, you need to define one more formatting rule and apply it to these columns:

formats: [
{
thousandsSeparator: ',',
decimalSeparator: '.',
decimalPlaces: 2,
maxDecimalPlaces: 2
},
{
name: 'total',
decimalPlaces: 0,
maxDecimalPlaces: 0,
},
],
slice: {
measures: [
{
uniqueName: 'Rate Group',
format: 'total',
},
{
uniqueName: 'Carrier',
format: 'total',
}

],
},

For more details on number formatting, we suggest referring to our documentation: https://www.flexmonster.com/doc/number-formatting/
 
Please let us know if the above code snippets were helpful.
 
Best regards,
Tanya

Public
Denis December 2, 2020

Yes, but it will show only columns Rate Group and Carrier. If I have another columns like First Name and Second Name this two columns will hidden. I need to display all 4 columns but Rate Group and Carrier with format "XX.XX"
For example I have 5 columns: Rate Group, Carrier, First Name, Second Name, Age. I need to display with format "XX.XX" Rate Group and Age, another cells let it be just "XX", can I do this withiut listing these columns in measures array? Because in real case I have more than 50 columns and it's imposible.
In real project I have > 50 columns and I need format "XX.XX" only for 2. If I list these 2 columns in measures array it will hide another 48 columns
 

Public
Tanya Gryshko Tanya Gryshko Flexmonster December 2, 2020

Denis,
 
Thank you for your quick response.
 
For your case, it would be more convenient to add the formatting with the help of our API calls. Please check the following example: http://jsfiddle.net/flexmonster/kc8fq69y/. It shows how to change the formatting when the measure was not specified in the slice. 
 
You can subscribe to the reportcomplete event and change the formatting once the component is loaded. 
 
We hope it helps.
 
Best regards,
Tanya
 

Public
Denis December 2, 2020

Tnx a lot

Please login or Register to Submit Answer