localization events

Events

by Flexmonster Pivot Table

HTML

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

<div>
  <p>
    Choose any localization to trigger the
    <code>loadinglocalization</code> event.
  </p>
  <p>
    After successfully loading the localization file, the
    <code>localizationloaded</code> event is triggered and outputs the message
    under the component.
  </p>
  <p>
    If there are any issues when loading the localization file, the
    <code>localizationerror</code> event is triggered and outputs the error
    message under the component.
  </p>
</div>

<button onclick="setLocalization('en')">English</button>
<button onclick="setLocalization('fr')">Français</button>
<button onclick="setLocalization('es')">Español</button>
<button onclick="setLocalization('pt')">Português</button>
<button onclick="setLocalization('zh')">中国的</button>
<button onclick="setLocalization('uk')">Українська</button>

<div id="pivot-container">The component will appear here</div>

<div class="output" id="output">Output will appear here</div>

CSS

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

JavaScript

function setLocalization(lang) {
  pivot.setReport({
    dataSource: {
      dataSourceType: "csv",
      filename: "data/data-" + lang + ".csv"
    },
    localization: "loc/" + lang + ".json"
  });
}

var pivot = new Flexmonster({
	container: "pivot-container",
  componentFolder: "https://cdn.flexmonster.com/",
  global: {
    localization: "loc/en.json"
  },
  report: {
    dataSource: {
      dataSourceType: "csv",
      filename: "data/data-en.csv"
    }
  },
  width: "100%",
  height: 340,
  toolbar: true
});

let outputInitialized = false;

function showOutput(content) {
  var log = "[" + (new Date()).toLocaleTimeString('en-US') + "] " + content;
  var outputElement = document.getElementById("output");
  if (!outputInitialized) {
    outputElement.innerText = '';
    outputInitialized = true;
  }
  outputElement.innerText += log + "\n";
  outputElement.scrollTop = outputElement.scrollHeight;
}

pivot.on('loadinglocalization', function () {
  showOutput('Loading localization file!');
});
pivot.on('localizationloaded', function () {
  showOutput('Localization file was loaded!');
});
pivot.on('localizationerror', function () {
  showOutput('Error with localization file!');
});