API calls setFilter, getFilter, clearFilter

Slice configuration

by Flexmonster Pivot Table

HTML

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

<p>
  Click the buttons below to apply the filter to the <code>Country</code> field.
</p>

<button onclick="setConditionalFilter()">Conditional Filter</button>
<button onclick="setSelectionFilter()">Selection Filter</button>
<button onclick="setSelectionFilterExclude()">
  Selection Filter (Exclude)
</button>
<button onclick="setValueFilter()">Value Filter</button>

<p>
  Click the <b>Get Filter</b> button to output info about the applied filter
  under the component.
</p>
<button onclick="getFilter()">Get Filter</button>

<p>
  Click the <b>Clear Filter</b> button to clear the filter applied for the
  <code>Country</code> field.
</p>

<button onclick="clearFilter()">Clear Filter</button>

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

<div class="output" id="output">Output will appear here</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/",
  height: 470,
  report: {
    dataSource: {
      filename: "data/retail-data.json",
    },
    slice: {
      rows: [
        {
          uniqueName: "Country",
        },
      ],
      columns: [
        {
          uniqueName: "[Measures]",
        },
      ],
      measures: [
        {
          uniqueName: "Price",
        },
      ],
    },
  },
});

function setConditionalFilter() {
  pivot.setFilter("Country", {
    query: {
      begin: "U",
    },
  });
}

function setSelectionFilter() {
  pivot.setFilter("Country", {
    members: [
      "country.[poland]", 
      "country.[uk]", 
      "country.[ukraine]"
    ],
  });
}

function setSelectionFilterExclude() {
  pivot.setFilter("Country", {
    exclude: [
      "country.[australia]",
      "country.[japan]",
      "country.[norway]",
      "country.[sweden]",
    ],
  });
}

function setValueFilter() {
  pivot.setFilter("Country", {
    query: {
      top: 5,
    },
    measure: {
      uniqueName: "Price",
      aggregation: "sum",
    },
  });
}

function getFilter() {
  let filter = pivot.getFilter("Country");
  showOutput(JSON.stringify(filter, null, 4));
}

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

function showOutput(content) {
  document.getElementById("output").innerText = content;
}