Flexmonster - Load JSON

Demos

by aivarsak

HTML

<link rel="stylesheet" href="https://s3.amazonaws.com/flexmonster/2.3/demo.css">
<script src="https://cdn.flexmonster.com/flexmonster.js"></script>

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

JavaScript

const customizeCell = (cell, data) => {
	const hierarchy = data.hierarchy;
  if (hierarchy && data.label) {
    if (data.type === 'value') {
    	if (hierarchy.caption === "Supplier Name") {
	      cell.text = `<a href="/ID/and/parentID/needed/here">${data.label}</a>`;
      }
    }
  }
}

const pivot = new Flexmonster({
  container: "#pivot-container",
  componentFolder: "https://cdn.flexmonster.com/",
  report: {
    dataSource: {
      dataSourceType: "json",
      data: getData()
    },
    options: {
	    grid: { type: 'flat' },
    },
    columns: [
    	{uniqueName: "Profit"},
      {uniqueName: "Supplier Name"},
    ]
  },
  width: "100%",
  height: 370,
  toolbar: true
});

function getData() {
  return [
  	{
    	id: {type: "id"},
      "Supplier Name": {caption: "Supplier Name", type: "string"},
      "Profit": {caption: "Profit", type: "number"},
      "Parent ID": {caption: "Parent ID", type: "hidden"},
    },
    {
    	id: 123,
      "Supplier Name": "Supplier 1",
      "Profit": 123,
      "Parent ID": 333,
    },
    {
    	id: 124,
      "Supplier Name": "Supplier 2",
      "Profit": 223,
      "Parent ID": 333,
    }
  ];
}