1

I tried recommendations given here.. but I still couldn't get specific column total details. e.g. v0. May I please request you to share details on how to extract specific column & row details in webdatarocks pivot without a cell selection.

I also reviewed recommendations given at Here. I need additional help..

learner
  • 29
  • 4
  • Please state your problem so that it can be understood without links to external sites or data. Only use these links to add extra information for those interested and willing to help. Also, make a clear statement about what your expected output should be. – Bart Barnard Mar 18 '21 at 09:20
  • I was unable to fetch column total & following code based on inputs from @Tanya Helped. let record = rawData.data[0]; console.log(">>>>>>" + record["v0"]); console.log(">>>>>>" + record["v1"]); – learner Mar 19 '21 at 03:54

1 Answers1

1

Below is a code snippet. Pay attention to the getTotals function - it shows how to get row and column totals while iterating getData response.

let pivot = new WebDataRocks({
    container: "#wdr-component",
    toolbar: true,
    report: {
    "dataSource": {
        "dataSourceType": "csv",
        "filename": "https://cdn.webdatarocks.com/data/data.csv"
    },
    "slice": {
        "rows": [
            {
                "uniqueName": "Category"
            }
        ],
        "columns": [
            {
                "uniqueName": "Business Type"
            },
            {
                "uniqueName": "Measures"
            }
        ],
        "measures": [
            {
                "uniqueName": "Price"
            }
        ]
    }
}
});

webdatarocks.getData({}, getTotals);

function getTotals(rawData) {
  let columnTotals = [];
  let rowTotals = [];
  for (let i = 0; i < rawData.data.length; i++) {
    let record = rawData.data[i];
    if (record["r0"] == undefined && record["c0"] == undefined) continue;
    if (record["r0"] == undefined) { 
      let _record = {
        member: record["c0"],
        value: !isNaN(record["v0"]) ? record["v0"] : 0
      };     columnTotals.push(_record);
    }
    if (record["c0"] == undefined) { 
      let _record = {
        member: record["r0"],
        value: !isNaN(record["v0"]) ? record["v0"] : 0
      };     rowTotals.push(_record);
    }
  } 
  console.log(columnTotals);
  console.log(rowTotals); 
}
<link href="https://cdn.webdatarocks.com/latest/webdatarocks.min.css" rel="stylesheet"/>
<script src="https://cdn.webdatarocks.com/latest/webdatarocks.toolbar.min.js"></script>
<script src="https://cdn.webdatarocks.com/latest/webdatarocks.js"></script>
<div id="wdr-component"></div>
Tanya
  • 76
  • 4
  • following two precise lines helped me solve this problem. so if one has a Datagrid with fixed columns following two lines can help one get the column total. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ let record = rawData.data[0]; console.log("First Total " + record["v0"]); console.log("SecondTotal" + record["v1"]); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ – learner Mar 19 '21 at 03:51