I am trying to create two pivot tables using pivottable.js to show payroll hours
the desired result would be like this:
Payroll for location 1
foo
bar
biz
Payroll for location 2
bad
bash
bin
obviously in the pivottable.js display form which I cannot recreate here
however, the pivottable only shows one for the page and it is either location 1 or location 2
I dont know enough about javascript or html to understand what I am doing wrong here, it seems like a simple problem that I just am not seeing. this is all within a php file.
here is the code I am using for the php file
$pageStart = '<html>
<head>
<title>Payroll</title>
<!-- c3 and d3 scripts and jquery -->
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/c3/0.4.11/c3.min.css">
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/c3/0.4.11/c3.min.js"></script>
<script type="text/javascript" src="./jquery/jquery-3.2.1.min.js"></script>
<script type="text/javascript" src="./jquery/jquery-ui-1.12.1/jquery-ui.min.js"></script>
<!-- PivotTable.js -->
<link rel="stylesheet" type="text/css" href="./jquery/pivottable/dist/pivot.css">
<script type="text/javascript" src="./jquery/pivottable/dist/pivot.js"></script>
<script type="text/javascript" src="./jquery/c3_renderers.js"></script>
<style>
body {font-family: Verdana;}
</style>
<!-- mobile support -->
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui-touch-punch/0.2.3/jquery.ui.touch-punch.min.js"></script>
</head>
<body>
<p> Location 1 payroll hours
<script type="text/javascript">
// This loads the payroll hours for location 1
// no derived attributes
var derivers = $.pivotUtilities.derivers;
var renderers = $.extend($.pivotUtilities.renderers,
$.pivotUtilities.c3_renderers);
$(function(NB){NB,
$("#output").pivotUI(
' . $json . ',
{rows: ["Name"],
cols: ["Hours_type", "Date"],
aggregatorName: "Sum",
vals: ["Hours"],}
);
});
</script>
<br>
<p> location 2 Payroll Hours
<script>
$(function(SV){
$("#output").pivotUI(SV,
' . $json2 . ',
{rows: ["Name"],
cols: ["Hours_type", "Date"],
aggregatorName: "Sum",
vals: ["Hours"],}
);
})
</script>
<div id="output" style="margin: 30px;"></div>
</body>
</html>';
print $pageStart;
the $json
and $json2
are mysql functions that pull the data for the pivottable to display
If you use $("#output") for both tables, then one will overwrite the other.