ピボットスライサーの概要

SpreadJSのピボットテーブルは、手動フィルターの便利なグラフィカルインターフェイスであるスライサーをサポートします。

SpreadJSのピボットテーブルは、手動フィルターの便利なグラフィカルインターフェイスであるスライサーをサポートします。 スライサー内の項目をクリックしてドラッグし、フィルタリングしてみてください。クリックまたはドラッグするときに、ShiftキーとCtrlキー(Windowsの場合)/コマンドキー(Macの場合)を押してみることもできます。
window.onload = function () { var spread = new GC.Spread.Sheets.Workbook(_getElementById('ss'), { sheetCount: 2 }); initSpread(spread); var pivotLayoutSheet = spread.getSheet(0); var pt = initPivotTable(pivotLayoutSheet); initSlicer(pt, pivotLayoutSheet); }; function initSpread(spread) { spread.suspendPaint(); let sheet = spread.getSheet(1); sheet.name("DataSource"); sheet.setRowCount(650); sheet.setColumnWidth(5, 120); sheet.getCell(-1, 5).formatter("YYYY-mm-DD"); sheet.getRange(-1,4,0,1).formatter("$ #,##0"); sheet.setArray(0, 0, pivotSales); let table = sheet.tables.add('tableSales', 0, 0, 637, 6); table.style(GC.Spread.Sheets.Tables.TableThemes["none"]); let sheet0 = spread.getSheet(0); sheet0.name("PivotLayout"); spread.resumePaint(); } function initPivotTable(sheet) { let myPivotTable = sheet.pivotTables.add("myPivotTable", "tableSales", 0, 0, GC.Spread.Pivot.PivotTableLayoutType.outline, GC.Spread.Pivot.PivotTableThemes.light8); myPivotTable.suspendLayout(); myPivotTable.options.showRowHeader = true; myPivotTable.options.showColumnHeader = true; myPivotTable.options.subtotalsPosition = GC.Spread.Pivot.SubtotalsPosition.top; myPivotTable.layoutType(GC.Spread.Pivot.PivotTableLayoutType.compact); myPivotTable.add("region", "Region", GC.Spread.Pivot.PivotTableFieldType.rowField); myPivotTable.add("country", "Country", GC.Spread.Pivot.PivotTableFieldType.rowField); myPivotTable.add("city", "City", GC.Spread.Pivot.PivotTableFieldType.rowField); let groupInfo = { originFieldName: "date", dateGroups: [{ by: GC.Pivot.DateGroupType.quarters }, {by: GC.Pivot.DateGroupType.years}, {by: GC.Pivot.DateGroupType.months}] }; myPivotTable.group(groupInfo); myPivotTable.add("amount", "Amounts", GC.Spread.Pivot.PivotTableFieldType.valueField, GC.Pivot.SubtotalType.sum); var panel = new GC.Spread.Pivot.PivotPanel("myPivotPanel", myPivotTable, document.getElementById("panel")); panel.sectionVisibility(GC.Spread.Pivot.PivotPanelSection.area); myPivotTable.resumeLayout(); myPivotTable.autoFitColumn(); return myPivotTable; } function initSlicer (pt, sheet) { var yearSlicer = sheet.slicers.add("Years", pt.name(), "年", GC.Spread.Sheets.Slicers.SlicerStyles.light5(), GC.Spread.Sheets.Slicers.SlicerType.pivotTable); var quarterSlicer = sheet.slicers.add("Quarters", pt.name(), "四半期", GC.Spread.Sheets.Slicers.SlicerStyles.light2(), GC.Spread.Sheets.Slicers.SlicerType.pivotTable); var monthSlicer = sheet.slicers.add("Months", pt.name(), "date", GC.Spread.Sheets.Slicers.SlicerStyles.light1(), GC.Spread.Sheets.Slicers.SlicerType.pivotTable); setSlicerProp(yearSlicer, 318, 20, 372, 60, 5, true, "Time Slicer Dashboard", null, false); setSlicerProp(quarterSlicer, 318, 80, 150, 180, 1, null, null, null, false); setSlicerProp(monthSlicer, 468, 80, 222, 180, 2, false, null, 17, false); var regionSlicer = sheet.slicers.add("Region", pt.name(), "Region", GC.Spread.Sheets.Slicers.SlicerStyles.dark1(), GC.Spread.Sheets.Slicers.SlicerType.pivotTable); var countrySlicer = sheet.slicers.add("Country", pt.name(), "Country", GC.Spread.Sheets.Slicers.SlicerStyles.dark2(), GC.Spread.Sheets.Slicers.SlicerType.pivotTable); var citySlicer = sheet.slicers.add("City", pt.name(), "City", GC.Spread.Sheets.Slicers.SlicerStyles.dark3(), GC.Spread.Sheets.Slicers.SlicerType.pivotTable); setSlicerProp(regionSlicer, 318, 280, 124, 200, 1, true, null, null, true) setSlicerProp(countrySlicer, 442, 280, 160, 200, 1, true, null, null, true) setSlicerProp(citySlicer, 602, 280, 146, 200, 1, true, null, null, true) } function setSlicerProp(slicer, x, y, width, height, columnCount, showHeader, captionName, itemHeight, showNoDataItemsInLast) { slicer.position({x, y}); slicer.width(width); slicer.height(height); if (columnCount) { slicer.columnCount(columnCount); } if (captionName) { slicer.captionName(captionName); } slicer.showHeader(!!showHeader); if (itemHeight) { slicer.itemHeight(itemHeight); } slicer.showNoDataItemsInLast(!!showNoDataItemsInLast); slicer.allowMove(false); slicer.allowResize(false); } function _getElementById(id) { return document.getElementById(id); }
<!doctype html> <html style="height:100%;font-size:14px;"> <head> <meta name="spreadjs culture" content="ja-jp" /> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <link rel="stylesheet" type="text/css" href="$DEMOROOT$/ja/purejs/node_modules/@grapecity/spread-sheets/styles/gc.spread.sheets.excel2013white.css"> <script src="$DEMOROOT$/ja/purejs/node_modules/@grapecity/spread-sheets/dist/gc.spread.sheets.all.min.js" type="text/javascript"></script> <script src="$DEMOROOT$/ja/purejs/node_modules/@grapecity/spread-sheets-shapes/dist/gc.spread.sheets.shapes.min.js" type="text/javascript"></script> <script src="$DEMOROOT$/ja/purejs/node_modules/@grapecity/spread-sheets-pivot-addon/dist/gc.spread.pivot.pivottables.min.js" type="text/javascript"></script> <script src="$DEMOROOT$/ja/purejs/node_modules/@grapecity/spread-sheets-resources-ja/dist/gc.spread.sheets.resources.ja.min.js" type="text/javascript"></script> <script src="$DEMOROOT$/spread/source/data/pivotSales.js" type="text/javascript"></script> <script src="$DEMOROOT$/spread/source/js/license.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 class="sample-panel"> <div id="panel"></div> </div> </div> </body> </html>
.sample-tutorial { position: relative; height: 100%; } .sample-spreadsheets { width: calc(100% - 300px); height: 100%; overflow: hidden; float: left; } body { position: absolute; top: 0; bottom: 0; left: 0; right: 0; overflow: hidden; } .sample-panel { float: right; width: 300px; padding: 12px; height: 100%; box-sizing: border-box; background: #fbfbfb; overflow: auto; } .gc-panel { padding: 10px; background-color: rgb(230, 230, 230); } #panel { position: absolute; right: 0; width: 300px; height: 100%; top: 0; } #app { height: 100%; }