0

我可以react-pivottable为表格值应用自定义格式吗?

例如,我必须得到count以两位小数显示的值的总和。但是,我想自定义这些小数位。

<template>
  <div id="app">
    <vue-custom-scrollbar class="scroll-area"  :settings="settings">
      <vue-pivottable height="720" width="1280"
              :data="pivotData"
              :aggregator-name="aggregatorName"
              :renderer-name="rendererName"
              :rows="rows"
              :cols="cols"
              :vals="vals"
              :row-total="true"
              :col-total="true"
              :inclusions ="inclusions"
              :sorters ="this.sortOrder()"
              :formatSettings="formatSettings"
          >
      </vue-pivottable>
    </vue-custom-scrollbar>
  </div>
</template>

<script>
import { VuePivottable} from 'vue-pivottable'
import 'vue-pivottable/dist/vue-pivottable.css'
import vueCustomScrollbar from 'vue-custom-scrollbar'
export default {
    components: {
        VuePivottable,
        vueCustomScrollbar
    },
    data: function(){
      return{       
        aggregatorName: 'Sum',
        rendererName: 'Table',
        rows: ['country', 'gender'],
        cols: ['year'],
        vals: ['count']
        }
      }
    },     
    computed: {
      pivotData: function () {
        const pivotData = [        
          {"country": "United States", "year": 2010, "gender": "male", "count": parseInt('153295220')},
          {"country": "United States", "year": 2010, "gender": "female", "count": parseInt('156588400')},
          {"country": "France", "year": 2012, "gender": "female", "count": parseInt('32612882')}
        ]
       
        return pivotData;
      }
    }
}
</script>

这是输出的图像: 输出图像

4

1 回答 1

0

如果你只想得到小数,你可以使用这个聚合器:

aggregatorName="Integer Sum"
于 2021-05-06T10:45:39.643 回答