API call setFilter for two fields

Slice configuration

by Flexmonster Pivot Table

HTML

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

<div>
  <h2>How to apply filters to several fields at once</h2>
  <p>
    To filter several fields at once, call the
    <a href="https://www.flexmonster.com/api/setfilter/" target="_blank"
    >setFilter</a> method successively with each field as a parameter.
  </p>
  <p>
    In this example, when you click the button to set a filter, the
    <code>setFilter</code> method is called two times: with the
    <code>Category</code> field as a parameter and with the
    <code>Country</code> field.
  </p>
</div>

<button onclick="setFilters()">Set a filter for two fields</button>
<button onclick="clearFilters()">Clear the filter</button>

<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/",
  report: {
    dataSource: {
      filename: "data/data.csv"
    },
    slice: {
      columns: [{
        uniqueName: "Category"
      }],
      rows: [{
        uniqueName: "Country"
      }, {
        uniqueName: "[Measures]"
      }],
      measures: [{
        uniqueName: "Price",
        format: "currency"
      }, {
        uniqueName: "Discount",
        format: "currency"
      }],
    },
    formats: [
    	{
      	name: "currency",
        decimalPlaces: 2,
        currencySymbol: "$"
      }
    ]
  }
});

function setFilters() {
  pivot.setFilter("Category", {
    "members": [
      "category.[bikes]",
      "category.[cars]"
    ]
  });
  pivot.setFilter("Country", {
    "members": [
      "country.[France",
      "country.[Germany]",
      "country.[United Kingdom]"
    ]
  });
}

function clearFilters() {
  pivot.clearFilter("Category");
  pivot.clearFilter("Country");
}