Format Cell Based on object value

Answered
Mariano asked on December 18, 2021

Hello,
I have a pivot in which I need to show amounts with 2 or 3 decimal places based on a property of the object.
The items in my report have the following structure:

{
   country: "Italy",
   Article: "Test Article",
   DecimalDigits: 2,
   "Amount": 20,20
}

{
   country: "Belgium",
   Article: "Test Article 2",
   DecimalDigits: 3,
   "Amount": 15,120
}

 

Decimal digits could be 2 or 3 for different articles and I need to show in the pivot the Amount with the correct number of decimal places.
 
this is my report structure:
 

{
      dataSource: {
        data: getData(),
       },
      slice: {
        rows: [
          {
            uniqueName: "Article",
          },
        ],
        columns: [
          {
            uniqueName: "[Measures]",
          },
          {
            uniqueName: "country",
          },
        ],
        measures: [
          {
            uniqueName: "Amount",
            aggregation: "sum",
          },
        ],
        expands: {
          expandAll: true,
        },
        drills: {
          drillAll: true,
        },
      },
      formats: [
        {
          name: "",
          thousandsSeparator: ",",
        },
      ],
      options: {
        grid: {
          type: "classic",
          showTotals: "off",
          showGrandTotals: "rows",
        },
      },
    };
  }

I would do something like:

  conditions:
      [
        {
          formula: "'DecimalDigits' = 2",
          measure: "Amount",
          format:
          {
            decimalPlaces: 2
          }
        },
        {
          formula: "'DecimalDigits' = 3",
          measure: "DecimalDigits",
          format:
          {
            decimalPlaces: 3
          }
        }
      ],

is it possible?
 
Thank you

1 answer

Public
Nadia Khodakivska Nadia Khodakivska Flexmonster December 21, 2021

Hello, Mariano,
 
Thank you for your response.
 
Currently, Flexmonster does not allow to apply different format objects to a single measure. We suggest customizeCell API call as a workaround. More information you can find in our documentation: https://www.flexmonster.com/api/customizecell/
Additionally, you can set "DecimalDigits" type to "id" in the mapping. So the "DecimalDigits" property will be accessible in the cell object(recordId property). It will allow to use its value to change the format.
 
Please let us know if such an approach would work for your case. Looking forward to your response.
 
Kind regards,
Nadia

Please login or Register to Submit Answer