Pivot Details

SpreadJS allows you to get the pivot details for any selected area and will return a two-dimensional array. Select any of the values in columns D to H to return the data.

In PivotTable of SpreadJS, pivot table show detail will find all merged data in data source: To get Pivot details, You can use the following API:
window.onload = function () { let spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"), {sheetCount: 2}); let detailsSpread = new GC.Spread.Sheets.Workbook(document.getElementById("pivot-details"), {sheetCount: 1}); initSpread(spread, detailsSpread); }; function initSpread(spread, detailsSpread) { spread.suspendPaint(); let sheet1 = spread.getSheet(0); let sheet2 = spread.getSheet(1); let tableName = getDataSource(sheet1, pivotSales); let pivotTable = initPivotTable(sheet2, tableName); spread.setActiveSheet("PivotTable"); let detailsSheet = detailsSpread.getSheet(0); detailsSheet.name("PivotTable Details"); addEvent(sheet2, detailsSheet, pivotTable); spread.resumePaint(); } function addEvent (sheet2, detailsSheet, pivotTable) { detailsSheet.setRowCount(700); detailsSheet.setColumnCount(10); detailsSheet.addSpan(0,0,2,6); let style = new GC.Spread.Sheets.Style(); style.wordWrap = true; detailsSheet.setStyle(0,0,style); detailsSheet.setValue(0,0,"In PivotTable of SpreadJS, pivot table show detail will find all merged data in data source"); sheet2.bind(GC.Spread.Sheets.Events.CellClick, (sender, args) => { detailsSheet.suspendPaint(); let dataSource = getPivotDetails(args.row, args.col, pivotTable); detailsSheet.tables.remove("details"); if (dataSource) { var table = detailsSheet.tables.add('details', 2, 0, dataSource.length, dataSource[0].length); table.style(GC.Spread.Sheets.Tables.TableThemes["none"]); } detailsSheet.getCell(-1, 0).formatter("YYYY-mm-DD"); detailsSheet.getRange(-1,4,0,2).formatter("$ #,##0"); detailsSheet.setColumnWidth(0, 120); detailsSheet.setArray(2, 0, dataSource); detailsSheet.resumePaint(); }); } function getPivotDetails (row, col, pivotTable) { let pivotInfo = pivotTable.getPivotInfo(row, col), detailsObj = []; if (!pivotInfo || pivotInfo.area !== 4) { return void 0; } let colInfo = pivotInfo.colInfos; let rowInfo = pivotInfo.rowInfos; setDetails(colInfo, detailsObj); setDetails(rowInfo, detailsObj); let dataSource = pivotTable.getPivotDetails(detailsObj); return dataSource; } function setDetails (rowOrColInfo, detailsObj) { if (rowOrColInfo && rowOrColInfo.length > 0) { for (let item of rowOrColInfo) { if (item.isGrandTotal) { break; } detailsObj.push({fieldName: item.fieldName, fieldItem: item.itemName}); } } } function getDataSource(sheet, tableSource){ sheet.name("DataSource"); sheet.setRowCount(117); sheet.setColumnWidth(0, 120); sheet.getCell(-1, 0).formatter("YYYY-mm-DD"); sheet.getRange(-1,4,0,2).formatter("$ #,##0"); let table = sheet.tables.add('table', 0, 0, 117, 6); for(let i=2;i<=117;i++) { sheet.setFormula(i-1,5,'=D'+i+'*E'+i) } table.style(GC.Spread.Sheets.Tables.TableThemes["none"]); sheet.setArray(0, 0, tableSource); return table.name(); } function initPivotTable(sheet, tableName){ sheet.name("PivotTable"); sheet.setRowCount(1000); let option = { showRowHeader:true, showColumnHeader:true, bandRows:true, bandColumns:true }; let pivotTable = sheet.pivotTables.add("pivotTable", tableName, 1, 1, GC.Spread.Pivot.PivotTableLayoutType.outline, GC.Spread.Pivot.PivotTableThemes.medium8,option); pivotTable.suspendLayout(); pivotTable.add("salesperson", "Salesperson", GC.Spread.Pivot.PivotTableFieldType.rowField); pivotTable.add("car", "Cars", GC.Spread.Pivot.PivotTableFieldType.rowField); pivotTable.add("date", "Date", GC.Spread.Pivot.PivotTableFieldType.columnField); let groupInfo = { originFieldName: "date", dateGroups: [{ by: GC.Pivot.DateGroupType.quarters }] }; pivotTable.group(groupInfo); pivotTable.add("total", "Totals", GC.Spread.Pivot.PivotTableFieldType.valueField, GC.Pivot.SubtotalType.sum); let style = new GC.Spread.Sheets.Style(); style.formatter = "$ #,##0"; pivotTable.setStyle({dataOnly: true}, style); pivotTable.resumeLayout(); pivotTable.autoFitColumn(); return pivotTable; }
<!doctype html> <html style="height:100%;font-size:14px;"> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <link rel="stylesheet" type="text/css" href="$DEMOROOT$/en/purejs/node_modules/@grapecity/spread-sheets/styles/gc.spread.sheets.excel2013white.css"> <script src="$DEMOROOT$/en/purejs/node_modules/@grapecity/spread-sheets/dist/gc.spread.sheets.all.min.js" type="text/javascript"></script> <script src="$DEMOROOT$/en/purejs/node_modules/@grapecity/spread-sheets-pivot-addon/dist/gc.spread.pivot.pivottables.min.js" type="text/javascript"></script> <script src="$DEMOROOT$/spread/source/js/license.js" type="text/javascript"></script> <script src="$DEMOROOT$/spread/source/data/pivot-data.js" type="text/javascript"></script> <script src="app.js" type="text/javascript"></script> <link rel="stylesheet" type="text/css" href="styles.css"> </head> <body> <div class="sample-tutorial"> <div id="ss" class="sample-spreadsheets"></div> <div id="pivot-details" class="sample-spreadsheets-details"> </div> </div> </html>
.sample-tutorial { position: relative; height: 100%; overflow: hidden; } body { position: absolute; top: 0; bottom: 0; left: 0; right: 0; } .sample-spreadsheets { width: 60%; height: 100%; overflow: hidden; float: left; } .sample-spreadsheets-details{ width: 40%; height: 100%; overflow: hidden; float: left; }