JavaScript UI Libraries & Blazor Components Suite – Smart UI › Forums › Table › Error loading data Pivot table › Reply To: Error loading data Pivot table
Thanks for the reply Martin, below an example that generate the error described:
HTML:
<!DOCTYPE html>
<html>
<head>
<meta>
<link rel=”stylesheet” type=”text/css”
href=”../smart.default.css” />
</head>
<body>
<button id=”showPivot”>Click</button>
<div id=’gridSkill’ style=”width: 90%;”>
<smart-pivot-table id=”grid1″></smart-pivot-table>
</div>
</body>
<script src=”../jquery-3.3.1.min.js”></script>
<script src=”../smart.pivottable.js”></script>
<script src=”../test.js”></script>
</html>
JS (test.js):
$(“#showPivot”).click(
function() {
loadPivot();
})
function loadPivot(){
var c='[{“id”:0,”reportsto”:null,”available”:true,”firstName”:”Lars”,”lastName”:”Ohno”,”name”:”Lars Ohno”,”productName”:”Caffe Espresso”,”price”:3,”quantity”:7,”total”:21,”date”:”2021-07-20T22:00:00.000Z”},{“id”:1,”reportsto”:10,”available”:true,”firstName”:”Michael”,”lastName”:”Saavedra”,”name”:”Michael Saavedra”,”productName”:”Caffe Latte”,”price”:4.5,”quantity”:4,”total”:18,”date”:”2021-09-18T22:00:00.000Z”},{“id”:2,”reportsto”:9,”available”:true,”firstName”:”Cheryl”,”lastName”:”Davolio”,”name”:”Cheryl Davolio”,”productName”:”Espresso con Panna”,”price”:3.25,”quantity”:7,”total”:22.75,”date”:”2021-09-30T22:00:00.000Z”},{“id”:3,”reportsto”:4,”available”:true,”firstName”:”Beate”,”lastName”:”Devling”,”name”:”Beate Devling”,”productName”:”Cappuccino”,”price”:5,”quantity”:7,”total”:35,”date”:”2021-06-22T22:00:00.000Z”},{“id”:4,”reportsto”:10,”available”:true,”firstName”:”Sven”,”lastName”:”Peterson”,”name”:”Sven Peterson”,”productName”:”Caramel Latte”,”price”:3.8,”quantity”:6,”total”:22.799999999999997,”date”:”2021-02-01T23:00:00.000Z”},{“id”:5,”reportsto”:14,”available”:false,”firstName”:”Andrew”,”lastName”:”Saavedra”,”name”:”Andrew Saavedra”,”productName”:”Caffe Americano”,”price”:2.5,”quantity”:9,”total”:22.5,”date”:”2021-01-09T23:00:00.000Z”},{“id”:6,”reportsto”:11,”available”:false,”firstName”:”Regina”,”lastName”:”Burke”,”name”:”Regina Burke”,”productName”:”Espresso Truffle”,”price”:1.75,”quantity”:4,”total”:7,”date”:”2021-05-09T22:00:00.000Z”},{“id”:7,”reportsto”:16,”available”:true,”firstName”:”Andrew”,”lastName”:”Nagase”,”name”:”Andrew Nagase”,”productName”:”Espresso con Panna”,”price”:3.25,”quantity”:6,”total”:19.5,”date”:”2021-04-15T22:00:00.000Z”},{“id”:8,”reportsto”:3,”available”:true,”firstName”:”Andrew”,”lastName”:”Winkler”,”name”:”Andrew Winkler”,”productName”:”Caffe Espresso”,”price”:3,”quantity”:11,”total”:33,”date”:”2021-05-16T22:00:00.000Z”},{“id”:9,”reportsto”:3,”available”:false,”firstName”:”Ian”,”lastName”:”Saylor”,”name”:”Ian Saylor”,”productName”:”Peppermint Mocha Twist”,”price”:4,”quantity”:6,”total”:24,”date”:”2021-07-10T22:00:00.000Z”},{“id”:10,”reportsto”:null,”available”:true,”firstName”:”Cheryl”,”lastName”:”Vileid”,”name”:”Cheryl Vileid”,”productName”:”Black Tea”,”price”:2.25,”quantity”:7,”total”:15.75,”date”:”2021-01-11T23:00:00.000Z”},{“id”:11,”reportsto”:1,”available”:true,”firstName”:”Regina”,”lastName”:”Devling”,”name”:”Regina Devling”,”productName”:”Espresso con Panna”,”price”:3.25,”quantity”:8,”total”:26,”date”:”2021-01-10T23:00:00.000Z”},{“id”:12,”reportsto”:null,”available”:true,”firstName”:”Andrew”,”lastName”:”Ohno”,”name”:”Andrew Ohno”,”productName”:”Caffe Espresso”,”price”:3,”quantity”:2,”total”:6,”date”:”2021-01-18T23:00:00.000Z”},{“id”:13,”reportsto”:12,”available”:true,”firstName”:”Beate”,”lastName”:”Bein”,”name”:”Beate Bein”,”productName”:”Espresso con Panna”,”price”:3.25,”quantity”:4,”total”:13,”date”:”2021-05-21T22:00:00.000Z”},{“id”:14,”reportsto”:16,”available”:true,”firstName”:”Shelley”,”lastName”:”Winkler”,”name”:”Shelley Winkler”,”productName”:”Caffe Espresso”,”price”:3,”quantity”:6,”total”:18,”date”:”2021-10-17T22:00:00.000Z”},{“id”:15,”reportsto”:null,”available”:false,”firstName”:”Yoshi”,”lastName”:”Ohno”,”name”:”Yoshi Ohno”,”productName”:”Doubleshot Espresso”,”price”:3.3,”quantity”:1,”total”:3.3,”date”:”2021-10-12T22:00:00.000Z”},{“id”:16,”reportsto”:14,”available”:true,”firstName”:”Yoshi”,”lastName”:”Murphy”,”name”:”Yoshi Murphy”,”productName”:”Black Tea”,”price”:2.25,”quantity”:6,”total”:13.5,”date”:”2021-05-19T22:00:00.000Z”},{“id”:17,”reportsto”:17,”available”:true,”firstName”:”Antoni”,”lastName”:”Petersen”,”name”:”Antoni Petersen”,”productName”:”Cappuccino”,”price”:5,”quantity”:7,”total”:35,”date”:”2021-06-23T22:00:00.000Z”},{“id”:18,”reportsto”:null,”available”:false,”firstName”:”Shelley”,”lastName”:”Burke”,”name”:”Shelley Burke”,”productName”:”Peppermint Mocha Twist”,”price”:4,”quantity”:10,”total”:40,”date”:”2021-07-01T22:00:00.000Z”},{“id”:19,”reportsto”:null,”available”:false,”firstName”:”Nancy”,”lastName”:”Nodier”,”name”:”Nancy Nodier”,”productName”:”Doubleshot Espresso”,”price”:3.3,”quantity”:6,”total”:19.799999999999997,”date”:”2021-06-24T22:00:00.000Z”},{“id”:20,”reportsto”:null,”available”:false,”firstName”:”Nancy”,”lastName”:”Petersen”,”name”:”Nancy Petersen”,”productName”:”White Chocolate Mocha”,”price”:3.6,”quantity”:10,”total”:36,”date”:”2021-01-21T23:00:00.000Z”},{“id”:21,”reportsto”:10,”available”:false,”firstName”:”Guylene”,”lastName”:”Peterson”,”name”:”Guylene Peterson”,”productName”:”Green Tea”,”price”:1.5,”quantity”:5,”total”:7.5,”date”:”2021-08-24T22:00:00.000Z”},{“id”:22,”reportsto”:11,”available”:false,”firstName”:”Shelley”,”lastName”:”Burke”,”name”:”Shelley Burke”,”productName”:”Caffe Americano”,”price”:2.5,”quantity”:7,”total”:17.5,”date”:”2021-08-18T22:00:00.000Z”},{“id”:23,”reportsto”:4,”available”:true,”firstName”:”Sven”,”lastName”:”Davolio”,”name”:”Sven Davolio”,”productName”:”Caramel Latte”,”price”:3.8,”quantity”:7,”total”:26.599999999999998,”date”:”2021-03-02T23:00:00.000Z”},{“id”:24,”reportsto”:null,”available”:false,”firstName”:”Mayumi”,”lastName”:”Petersen”,”name”:”Mayumi Petersen”,”productName”:”White Chocolate Mocha”,”price”:3.6,”quantity”:7,”total”:25.2,”date”:”2021-05-25T22:00:00.000Z”},{“id”:25,”reportsto”:11,”available”:true,”firstName”:”Mayumi”,”lastName”:”Winkler”,”name”:”Mayumi Winkler”,”productName”:”Caffe Latte”,”price”:4.5,”quantity”:9,”total”:40.5,”date”:”2021-04-08T22:00:00.000Z”},{“id”:26,”reportsto”:2,”available”:true,”firstName”:”Elio”,”lastName”:”Petersen”,”name”:”Elio Petersen”,”productName”:”Cappuccino”,”price”:5,”quantity”:3,”total”:15,”date”:”2021-01-06T23:00:00.000Z”},{“id”:27,”reportsto”:7,”available”:true,”firstName”:”Michael”,”lastName”:”Bjorn”,”name”:”Michael Bjorn”,”productName”:”Caffe Espresso”,”price”:3,”quantity”:3,”total”:9,”date”:”2021-04-30T22:00:00.000Z”},{“id”:28,”reportsto”:null,”available”:false,”firstName”:”Cheryl”,”lastName”:”Rossi”,”name”:”Cheryl Rossi”,”productName”:”Peppermint Mocha Twist”,”price”:4,”quantity”:2,”total”:8,”date”:”2021-02-07T23:00:00.000Z”},{“id”:29,”reportsto”:6,”available”:true,”firstName”:”Yoshi”,”lastName”:”Rossi”,”name”:”Yoshi Rossi”,”productName”:”Caffe Latte”,”price”:4.5,”quantity”:9,”total”:40.5,”date”:”2021-09-02T22:00:00.000Z”},{“id”:30,”reportsto”:15,”available”:true,”firstName”:”Cheryl”,”lastName”:”Murphy”,”name”:”Cheryl Murphy”,”productName”:”Caffe Espresso”,”price”:3,”quantity”:9,”total”:27,”date”:”2021-07-02T22:00:00.000Z”},{“id”:31,”reportsto”:11,”available”:false,”firstName”:”Regina”,”lastName”:”Devling”,”name”:”Regina Devling”,”productName”:”Caffe Americano”,”price”:2.5,”quantity”:8,”total”:20,”date”:”2021-08-05T22:00:00.000Z”},{“id”:32,”reportsto”:11,”available”:false,”firstName”:”Andrew”,”lastName”:”Devling”,”name”:”Andrew Devling”,”productName”:”Caffe Americano”,”price”:2.5,”quantity”:4,”total”:10,”date”:”2021-04-08T22:00:00.000Z”},{“id”:33,”reportsto”:6,”available”:true,”firstName”:”Petra”,”lastName”:”Saavedra”,”name”:”Petra Saavedra”,”productName”:”Caffe Espresso”,”price”:3,”quantity”:2,”total”:6,”date”:”2021-07-24T22:00:00.000Z”},{“id”:34,”reportsto”:10,”available”:false,”firstName”:”Yoshi”,”lastName”:”Devling”,”name”:”Yoshi Devling”,”productName”:”White Chocolate Mocha”,”price”:3.6,”quantity”:1,”total”:3.6,”date”:”2021-08-18T22:00:00.000Z”},{“id”:35,”reportsto”:5,”available”:false,”firstName”:”Yoshi”,”lastName”:”Winkler”,”name”:”Yoshi Winkler”,”productName”:”Caffe Americano”,”price”:2.5,”quantity”:10,”total”:25,”date”:”2021-03-21T23:00:00.000Z”},{“id”:36,”reportsto”:null,”available”:false,”firstName”:”Michael”,”lastName”:”Petersen”,”name”:”Michael Petersen”,”productName”:”Caffe Americano”,”price”:2.5,”quantity”:4,”total”:10,”date”:”2021-01-10T23:00:00.000Z”},{“id”:37,”reportsto”:2,”available”:true,”firstName”:”Yoshi”,”lastName”:”Saylor”,”name”:”Yoshi Saylor”,”productName”:”Caffe Espresso”,”price”:3,”quantity”:3,”total”:9,”date”:”2021-05-14T22:00:00.000Z”},{“id”:38,”reportsto”:2,”available”:true,”firstName”:”Lars”,”lastName”:”Saylor”,”name”:”Lars Saylor”,”productName”:”Cappuccino”,”price”:5,”quantity”:7,”total”:35,”date”:”2021-06-23T22:00:00.000Z”},{“id”:39,”reportsto”:null,”available”:false,”firstName”:”Mayumi”,”lastName”:”Nodier”,”name”:”Mayumi Nodier”,”productName”:”Peppermint Mocha Twist”,”price”:4,”quantity”:10,”total”:40,”date”:”2021-09-30T22:00:00.000Z”},{“id”:40,”reportsto”:3,”available”:true,”firstName”:”Andrew”,”lastName”:”Winkler”,”name”:”Andrew Winkler”,”productName”:”Caramel Latte”,”price”:3.8,”quantity”:8,”total”:30.4,”date”:”2021-02-21T23:00:00.000Z”},{“id”:41,”reportsto”:8,”available”:false,”firstName”:”Nancy”,”lastName”:”Bjorn”,”name”:”Nancy Bjorn”,”productName”:”Caffe Americano”,”price”:2.5,”quantity”:9,”total”:22.5,”date”:”2021-02-05T23:00:00.000Z”},{“id”:42,”reportsto”:6,”available”:true,”firstName”:”Elio”,”lastName”:”Nodier”,”name”:”Elio Nodier”,”productName”:”Caffe Latte”,”price”:4.5,”quantity”:4,”total”:18,”date”:”2021-07-12T22:00:00.000Z”},{“id”:43,”reportsto”:6,”available”:true,”firstName”:”Regina”,”lastName”:”Petersen”,”name”:”Regina Petersen”,”productName”:”Caffe Latte”,”price”:4.5,”quantity”:9,”total”:40.5,”date”:”2021-11-20T23:00:00.000Z”},{“id”:44,”reportsto”:3,”available”:true,”firstName”:”Shelley”,”lastName”:”Murphy”,”name”:”Shelley Murphy”,”productName”:”Caramel Latte”,”price”:3.8,”quantity”:1,”total”:3.8,”date”:”2021-05-09T22:00:00.000Z”},{“id”:45,”reportsto”:9,”available”:false,”firstName”:”Ian”,”lastName”:”Bein”,”name”:”Ian Bein”,”productName”:”Doubleshot Espresso”,”price”:3.3,”quantity”:9,”total”:29.7,”date”:”2021-01-16T23:00:00.000Z”},{“id”:46,”reportsto”:14,”available”:true,”firstName”:”Elio”,”lastName”:”Bein”,”name”:”Elio Bein”,”productName”:”Caffe Latte”,”price”:4.5,”quantity”:9,”total”:40.5,”date”:”2021-08-12T22:00:00.000Z”},{“id”:47,”reportsto”:12,”available”:true,”firstName”:”Martin”,”lastName”:”Vileid”,”name”:”Martin Vileid”,”productName”:”Caffe Latte”,”price”:4.5,”quantity”:5,”total”:22.5,”date”:”2021-08-02T22:00:00.000Z”},{“id”:48,”reportsto”:1,”available”:true,”firstName”:”Lars”,”lastName”:”Ohno”,”name”:”Lars Ohno”,”productName”:”Black Tea”,”price”:2.25,”quantity”:9,”total”:20.25,”date”:”2021-07-31T22:00:00.000Z”},{“id”:49,”reportsto”:12,”available”:false,”firstName”:”Regina”,”lastName”:”Nagase”,”name”:”Regina Nagase”,”productName”:”Peppermint Mocha Twist”,”price”:4,”quantity”:5,”total”:20,”date”:”2021-06-05T22:00:00.000Z”}]’;
var result=JSON.parse(c);
window.Smart(‘#grid1’, class {
get properties() {
return {
dataSource: new window.Smart.DataAdapter({
dataSource: result,
dataFields: [
‘firstName: string’,
‘lastName: string’,
‘productName: string’,
‘quantity: number’,
‘price: number’,
‘date: date’
]
}),
freezeHeader: true,
keyboardNavigation: true,
selection: true,
columns: [
{ label: ‘First Name’, dataField: ‘firstName’, dataType: ‘string’ },
{ label: ‘Last Name’, dataField: ‘lastName’, dataType: ‘string’, allowRowGroup: true, rowGroup: true },
{ label: ‘Product Name’, dataField: ‘productName’, dataType: ‘string’, allowPivot: true, pivot: true },
{ label: ‘Quantity’, dataField: ‘quantity’, dataType: ‘number’, summary: ‘sum’ },
{ label: ‘Price’, dataField: ‘price’, dataType: ‘number’, summary: ‘sum’, summarySettings: { prefix: ‘$’, decimalPlaces: 2 } },
{ label: ‘Date Purchased’, dataField: ‘date’, dataType: ‘date’ }
]
};
}
});
}
The function loadPivot only works if it is called on page load, not at the click of the button.
Where is the error? Thanks