datachanged

Events

by Flexmonster Pivot Table

HTML

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

<div>
  <p>
    Edit a cell's data on the grid to trigger the
    <code>datachanged</code> event. As a result, info about the changed cell
    will be output under the component.
  </p>
  <p>
    Notice that cells in the <code>Country</code> column cannot be edited
    because its
    <a
      target="_blank"
      href="https://www.flexmonster.com/api/field-mapping-object/#editing"
    >editing</a> mapping property is set to <code>false</code>.
  </p>
</div>

<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

var pivot = new Flexmonster({
  container: "pivot-container",
  componentFolder: "https://cdn.flexmonster.com/",
  height: 340,
  report: {
    dataSource: {
      data: getData(),
      mapping: {
        "Color": {
          type: "string"
        },
        "Country": {
          type: "string",
          editing: false
        },
        "RowId": {
          type: "id"
        },
        "Price": {
          type: "number"
        }
      }
    },
    options: {
      grid: {
        type: "flat"
      },
      editing: 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('datachanged', function(e) {
  showOutput("Data changed field: " +
    e.data[0].field +
    ", row id: " +
    e.data[0].id +
    ", new value: " +
    e.data[0].value +
    ", previous value: " +
    e.data[0].oldValue);
});


function getData() {
  return [
    {
      "Color": "green",
      "Country": "USA",
      "RowId": 1,
      "Price": 174
    },
    {
      "Color": "red",
      "Country": "Canada",
      "RowId": 2,
      "Price": 30
    },
    {
      "Color": "blue",
      "Country": "France",
      "RowId": 3,
      "Price": 283
    },
    {
      "Color": "purple",
      "Country": "Germany",
      "RowId": 4,
      "Price": 371
    }
  ];
}