Define available aggregations for fields of a certain type

Mapping configuration

by Flexmonster Pivot Table

HTML

<script src="https://cdn.flexmonster.com/flexmonster.js"></script>

<div>
  <h2>How to define available aggregations for fields of a certain type</h2>
  <p>
    In Flexmonster, it's possible to define available aggregations for all
    fields of a <code>"number"</code>, <code>"string"</code>,
    <code>"date string"</code>, or <code>"time"</code> type. This feature is
    supported for JSON, CSV, and the custom data source API.
  </p>
  <p>
    For the custom data source API, aggregations for fields of a certain type
    should be defined in a response to the /fields request.
    <a
      href="https://www.flexmonster.com/api/fields-request/#aggregations"
      target="_blank"
    >Learn more in our documentation</a>.
  </p>
  <p>
    For JSON and CSV, we define aggregations for fields of a certain type using
    the <code>mapping.aggregations.[field_type]</code> property. In the below
    example, the following aggregations are defined:
  </p>
  <ul>
    <li>
      <code>"sum"</code> and <code>"average"</code> aggregations for number
      fields.
    </li>
    <li>
      <code>"max"</code> and <code>"min"</code> aggregations for date fields.
    </li>
    <li>
      <code>"count"</code> and <code>"distinctcount"</code> aggregations for
      string fields.
    </li>
  </ul>
  <p>
    <a
      href="https://www.flexmonster.com/doc/mapping/#aggregations-for-field-types"
      target="_blank"
    >Visit our docs to learn more about this feature</a>.
  </p>
</div>

<div id="pivot-container"></div>

CSS

@import url(https://cdn.flexmonster.com/assets/jsfiddle-styles.css);

JavaScript

let pivot = new Flexmonster({
  container: "pivot-container",
  componentFolder: "https://cdn.flexmonster.com/",
  toolbar: true,
  report: {
    dataSource: {
      filename: "https://cdn.flexmonster.com/data/retail-data.json",
      mapping: {
        aggregations: {  
          number: [ "sum", "average" ],
          date: [ "max", "min" ],
          string: [ "count", "distinctcount" ]
        },
      	"Date": {
        	type: "date string"
        },
        "Order Date": {
        	type: "date string"
        },
      }
    },
    slice: {
      rows: [{
          uniqueName: "Country",
          filter: {
          	measure: {
            	uniqueName: "Price",
             	aggregation: "sum"
            },
          	query: {
            	top: 10
            }
          }
        }
      ],
      columns: [
        {
          uniqueName: "[Measures]"
        }
      ],
      measures: [
        { 
        	uniqueName: "Price" 
        },
        {
        	uniqueName: "Date"
        },
        {
        	uniqueName: "Deal Size"
        }
      ]
    },
    options: {
    	grid: {
        showGrandTotals: "off"
      }	
    }
  }
});