사용자 정의 피벗 테이블

SpreadJS에서는 응용 프로그램의 필요에 따라 피벗 테이블의 모양 및 기능을 사용자 정의할 수 있는 여러 가지 옵션을 제공합니다. 아래에서 여러 옵션을 편집한 다음 아래로 스크롤하여 적용 버튼을 누르면 편집한 결과를 확인할 수 있습니다.

피벗 테이블은 여러 가지 매개 변수로 구성할 수 있습니다. 피벗 테이블에 사용할 수 있는 매개 변수는 다음과 같습니다. allowMultipleFiltersPerField: 필드 하나에서 필터를 여러 개 사용할 수 있는지 여부입니다. insertBlankLineAfterEachItem: 각 항목의 끝에 빈 행을 삽입해야 하는지 여부입니다. grandTotalPosition: 행, 열 또는 둘 다에 총합계를 표시합니다. subtotalsPosition: 부분합을 위쪽 또는 아래쪽에 표시하거나 표시하지 않습니다. displayFieldsInPageFilterArea: 페이지 영역 필드를 먼저 위에 표시한 다음 아래에 표시하거나, 먼저 아래에 표시한 다음 위에 표시합니다. reportFilterFieldsPerColumn: 열당 보고서 필터 필드 수입니다. bandRows: 줄무늬 행을 표시할지 여부입니다. bandColumns: 줄무늬 열을 표시할지 여부입니다. showRowHeader: 행 머리글 스타일을 표시할지 여부입니다. showColumnHeader: 열 머리글 스타일을 표시할지 여부입니다. showDrill: 확장/축소 버튼을 표시할지 여부입니다. showMissing: 누락된 캡션을 표시할지 여부입니다. showToolTip: 도구 설명을 표시할지 여부입니다. missingCaption: 콘텐츠 영역의 빈 셀을 사용자 정의 문자열 또는 숫자로 바꿉니다. fillDownLabels: 레이블 항목 반복을 표시할지 여부입니다. repeatAllItemLabels: 레이블 항목 반복을 표시할지 여부입니다. rowLabelIndent: 컴팩트 레이아웃에서 제목 수준마다 들여쓰기를 설정합니다. mergeItem: 레이블이 있는 셀을 병합하고 가운데에 맞춥니다. showHeaders: 행 및 열 헤더를 표시하거나 표시하지 않습니다.
import * as React from 'react'; import * as ReactDOM from 'react-dom'; import './styles.css'; import { AppFunc } from './app-func'; import { App } from './app-class'; // 1. Functional Component sample ReactDOM.render(<AppFunc />, document.getElementById('app')); // 2. Class Component sample // ReactDOM.render(<App />, document.getElementById('app'));
import * as React from 'react'; import GC from '@mescius/spread-sheets'; import "@mescius/spread-sheets-shapes"; import "@mescius/spread-sheets-pivot-addon"; import { SpreadSheets } from '@mescius/spread-sheets-react'; import '@mescius/spread-sheets-resources-ko'; GC.Spread.Common.CultureManager.culture("ko-kr"); import './styles.css'; const useState = React.useState; function PivotOption(props) { return (<div className="option-item"> <input type="checkbox" id={props.value} name={props.value} value={props.value} class="select-option" checked={props.checked} onChange={props.onChange}></input> <label for={props.value}>{props.text}</label> </div>); } export function AppFunc() { const [pivotTable, setPivotTable] = useState(null); const [state, setState] = useState({ option: { allowMultipleFiltersPerField: false, insertBlankLineAfterEachItem: false, fillDownLabels: false, bandRows: true, bandColumns: true, showRowHeader: true, showColumnHeader: true, showDrill: true, showFilter: true, showMissing: true, showToolTip: true, mergeItem: false, showHeaders: true }, grandTotalPosition: 3, displayFieldsInPageFilterArea: 1, subtotalsPosition: 2, pivotTableLayout: 1, missingCaption: null, reportFilterFieldsPerColumn: 1, rowLabelIndent: null }); const handleSetOption = () => { pivotTable.suspendLayout(); let actualOption = state.option; let option = pivotTable.options, item; for (item in actualOption) { if (Object.prototype.hasOwnProperty.call(actualOption, item)) { option[item] = actualOption[item]; } } option["grandTotalPosition"] = parseInt(state.grandTotalPosition, 10); option["subtotalsPosition"] = parseInt(state.subtotalsPosition, 10); option["displayFieldsInPageFilterArea"] = parseInt(state.displayFieldsInPageFilterArea, 10); option["reportFilterFieldsPerColumn"] = state.reportFilterFieldsPerColumn; let rowLabelIndent = state.rowLabelIndent; let missingCaption = state.missingCaption; option["missingCaption"] = state.missingCaption; if (!isNaN(parseFloat(missingCaption))) { option["missingCaption"] = parseFloat(missingCaption); } else { option["missingCaption"] = missingCaption; } if (!isNaN(parseFloat(rowLabelIndent))) { option["rowLabelIndent"] = parseFloat(rowLabelIndent); } pivotTable.layoutType(+state.pivotTableLayout); pivotTable.resumeLayout(); } const handleInputClick = (event) => { const target = event.target; const value = target.checked; const name = target.name; let option = { ...state.option, [name]: value }; setState((state) => ({ ...state, option })); } const handleInputChange = (event) => { const target = event.target; const value = target.value; const name = target.name; setState((state) => ({ ...state, [name]: value })); } const initSpread = (spread) => { spread.suspendPaint(); spread.setSheetCount(2); let sheet1 = spread.getSheet(0); let sheet2 = spread.getSheet(1); let tableName = getDataSource(sheet2, pivotSales); let pt = initPivotTable(sheet1, tableName); setPivotTable(pt); spread.resumePaint(); } const 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(); } const initPivotTable = (sheet, source) => { sheet.name("PivotTable"); sheet.setRowCount(1000); let option = { bandRows: true, bandColumns: true }; let pt = sheet.pivotTables.add("pivotTable", source, 1, 1, GC.Spread.Pivot.PivotTableLayoutType.outline, GC.Spread.Pivot.PivotTableThemes.medium8, option); pt.suspendLayout(); pt.add("quantity", "Quantity", GC.Spread.Pivot.PivotTableFieldType.filterField); pt.add("price", "Price", GC.Spread.Pivot.PivotTableFieldType.filterField); pt.add("salesperson", "Salesperson", GC.Spread.Pivot.PivotTableFieldType.rowField); pt.add("car", "Cars", GC.Spread.Pivot.PivotTableFieldType.rowField); let groupInfo = { originFieldName: "date", dateGroups: [{ by: GC.Pivot.DateGroupType.quarters }] }; pt.group(groupInfo); pt.add("분기 (date)", "분기 (date)", GC.Spread.Pivot.PivotTableFieldType.columnField); pt.add("total", "Totals", GC.Spread.Pivot.PivotTableFieldType.valueField, GC.Pivot.SubtotalType.sum); let style = new GC.Spread.Sheets.Style(); style.formatter = "$ #,##0"; pt.setStyle({ dataOnly: true }, style); pt.resumeLayout(); pt.autoFitColumn(); return pt; } return ( <div class="sample-tutorial"> <div class="sample-spreadsheets"> <SpreadSheets workbookInitialized={spread => initSpread(spread)}> </SpreadSheets> </div> <div id="container" class="options-container"> <div class="option-item"> <label><b>Pivot Options</b></label> </div> <hr /> <PivotOption value={'allowMultipleFiltersPerField'} text="Allow Multiple Filters Per Field" checked={state.option.allowMultipleFiltersPerField} onChange={handleInputClick}></PivotOption> <PivotOption value={'insertBlankLineAfterEachItem'} text="Insert Blank Line After Each Item" checked={state.option.insertBlankLineAfterEachItem} onChange={handleInputClick}></PivotOption> <PivotOption value={'fillDownLabels'} text="fillDownLabels" checked={state.option.fillDownLabels} onChange={handleInputClick}></PivotOption> <PivotOption value={'bandRows'} text="Band Rows" checked={state.option.bandRows} onChange={handleInputClick}></PivotOption> <PivotOption value={'bandColumns'} text="Band Columns" checked={state.option.bandColumns} onChange={handleInputClick}></PivotOption> <PivotOption value={'showRowHeader'} text="Show Row Header" checked={state.option.showRowHeader} onChange={handleInputClick}></PivotOption> <PivotOption value={'showColumnHeader'} text="Show Column Header" checked={state.option.showColumnHeader} onChange={handleInputClick}></PivotOption> <PivotOption value={'showDrill'} text="Show Drill" checked={state.option.showDrill} onChange={handleInputClick}></PivotOption> <PivotOption value={'showFilter'} text="Show Filter" checked={state.option.showFilter} onChange={handleInputClick}></PivotOption> <PivotOption value={'showMissing'} text="Show Missing" checked={state.option.showMissing} onChange={handleInputClick}></PivotOption> <PivotOption value={'showToolTip'} text="Show ToolTip" checked={state.option.showToolTip} onChange={handleInputClick}></PivotOption> <PivotOption value={'mergeItem'} text="Merge Item" checked={state.option.mergeItem} onChange={handleInputClick}></PivotOption> <PivotOption value={'showHeaders'} text="showHeaders" checked={state.option.showHeaders} onChange={handleInputClick}></PivotOption> <hr /> <div> <div class="select-option-class">Grand Total Position:</div> <select value={state.grandTotalPosition} name="grandTotalPosition" id="grandTotalPosition" class="grandTotalPosition select-option-select" onChange={handleInputChange}> <option value="0">none</option> <option value="1">row</option> <option value="2">col</option> <option value="3">both</option> </select> </div> <div> <div class="select-option-class">Subtotals Position:</div> <select value={state.subtotalsPosition} name="subtotalsPosition" id="subtotalsPosition" class="subtotalsPosition select-option-select" onChange={handleInputChange}> <option value="2">bottom</option> <option value="0">none</option> <option value="1">top</option> </select> </div> <div> <div class="select-option-class">Display Fields In Page Filter Area:</div> <select value={state.displayFieldsInPageFilterArea} name="displayFieldsInPageFilterArea" id="displayFieldsInPageFilterArea" class="displayFieldsInPageFilterArea select-option-select" onChange={handleInputChange}> <option value="1">overThenDown</option> <option value="0">downThenOver</option> </select> </div> <div> <div class="select-option-class">PivotTable Layout:</div> <select id="pivotTableLayout" class="pivotTableLayout select-option-select" name="pivotTableLayout" value={state.pivotTableLayout} onChange={handleInputChange}> <option value="0">Compact</option> <option value="1">Outline</option> <option value="2">Tabular</option> </select> </div> <div> <div class="select-option-class">Show Empty Value In Content Area As:</div> <input type="text" name="missingCaption" id="missingCaption" class="missingCaption select-option-select" value={state.missingCaption} onChange={handleInputChange} /> </div> <div> <div class="select-option-class">Set Row Label Indent In Compact Layout:</div> <input type="number" name="rowLabelIndent" id="rowLabelIndent" class="rowLabelIndent select-option-select" value={state.rowLabelIndent} onChange={handleInputChange} /> </div> <div> <label for="reportFilterFieldsPerColumn">Report Filter Fields Per Column:</label> <input type="number" name="reportFilterFieldsPerColumn" id="reportFilterFieldsPerColumn" min="1" value={state.reportFilterFieldsPerColumn} onChange={handleInputChange}></input> </div> <input type="button" value="Apply" class="set-option" id="set-option" onClick={handleSetOption}></input> </div> </div> ); }
import * as React from 'react'; import GC from '@mescius/spread-sheets'; import "@mescius/spread-sheets-shapes"; import "@mescius/spread-sheets-pivot-addon"; import { SpreadSheets } from '@mescius/spread-sheets-react'; import '@mescius/spread-sheets-resources-ko'; GC.Spread.Common.CultureManager.culture("ko-kr"); import './styles.css'; const Component = React.Component; function PivotOption(props) { return (<div className="option-item"> <input type="checkbox" id={props.value} name={props.value} value={props.value} class="select-option" checked={props.checked} onChange={props.onChange}></input> <label for={props.value}>{props.text}</label> </div>); } export class App extends Component { constructor(props) { super(props); this.state = { renderChild: false, option: { allowMultipleFiltersPerField: false, insertBlankLineAfterEachItem: false, fillDownLabels: false, bandRows: true, bandColumns: true, showRowHeader: true, showColumnHeader: true, showDrill: true, showFilter: true, showMissing: true, showToolTip: true, mergeItem: false, showHeaders: true }, grandTotalPosition: 3, displayFieldsInPageFilterArea: 1, subtotalsPosition: 2, pivotTableLayout: 1, missingCaption: null, reportFilterFieldsPerColumn: 1, rowLabelIndent: null } this.handleSetOption = this.handleSetOption.bind(this); this.handleInputChange = this.handleInputChange.bind(this); this.handleInputClick = this.handleInputClick.bind(this); } handleSetOption() { let pivotTable = this.pivotTable; let state = this.state; pivotTable.suspendLayout(); let actualOption = state.option; let option = pivotTable.options, item; for (item in actualOption) { if (Object.prototype.hasOwnProperty.call(actualOption, item)) { option[item] = actualOption[item]; } } option["grandTotalPosition"] = parseInt(state.grandTotalPosition, 10); option["subtotalsPosition"] = parseInt(state.subtotalsPosition, 10); option["displayFieldsInPageFilterArea"] = state.displayFieldsInPageFilterArea; option["reportFilterFieldsPerColumn"] = state.reportFilterFieldsPerColumn; let rowLabelIndent = state.rowLabelIndent; let missingCaption = state.missingCaption; option["missingCaption"] = state.missingCaption; if (!isNaN(parseFloat(missingCaption))) { option["missingCaption"] = parseFloat(missingCaption); } else { option["missingCaption"] = missingCaption; } if (!isNaN(parseFloat(rowLabelIndent))) { option["rowLabelIndent"] = parseFloat(rowLabelIndent); } pivotTable.layoutType(+state.pivotTableLayout); pivotTable.resumeLayout(); } handleInputClick(event) { const target = event.target; const value = target.checked; const name = target.name; let option = this.state.option; option[name] = value; this.setState({ option }); } handleInputChange(event) { const target = event.target; const value = target.value; const name = target.name; this.setState({ [name]: value }); } render() { return ( <div class="sample-tutorial"> <div class="sample-spreadsheets"> <SpreadSheets workbookInitialized={spread => this.initSpread(spread)}> </SpreadSheets> </div> <div id="container" class="options-container"> <div class="option-item"> <label><b>Pivot Options</b></label> </div> <hr /> <PivotOption value={'allowMultipleFiltersPerField'} text="Allow Multiple Filters Per Field" checked={this.state.option.allowMultipleFiltersPerField} onChange={this.handleInputClick}></PivotOption> <PivotOption value={'insertBlankLineAfterEachItem'} text="Insert Blank Line After Each Item" checked={this.state.option.insertBlankLineAfterEachItem} onChange={this.handleInputClick}></PivotOption> <PivotOption value={'fillDownLabels'} text="fillDownLabels" checked={this.state.option.fillDownLabels} onChange={this.handleInputClick}></PivotOption> <PivotOption value={'bandRows'} text="Band Rows" checked={this.state.option.bandRows} onChange={this.handleInputClick}></PivotOption> <PivotOption value={'bandColumns'} text="Band Columns" checked={this.state.option.bandColumns} onChange={this.handleInputClick}></PivotOption> <PivotOption value={'showRowHeader'} text="Show Row Header" checked={this.state.option.showRowHeader} onChange={this.handleInputClick}></PivotOption> <PivotOption value={'showColumnHeader'} text="Show Column Header" checked={this.state.option.showColumnHeader} onChange={this.handleInputClick}></PivotOption> <PivotOption value={'showDrill'} text="Show Drill" checked={this.state.option.showDrill} onChange={this.handleInputClick}></PivotOption> <PivotOption value={'showFilter'} text="Show Filter" checked={this.state.option.showFilter} onChange={this.handleInputClick}></PivotOption> <PivotOption value={'showMissing'} text="Show Missing" checked={this.state.option.showMissing} onChange={this.handleInputClick}></PivotOption> <PivotOption value={'showToolTip'} text="Show ToolTip" checked={this.state.option.showToolTip} onChange={this.handleInputClick}></PivotOption> <PivotOption value={'mergeItem'} text="Merge Item" checked={this.state.option.mergeItem} onChange={this.handleInputClick}></PivotOption> <PivotOption value={'showHeaders'} text="showHeaders" checked={this.state.option.showHeaders} onChange={this.handleInputClick}></PivotOption> <hr /> <div> <div class="select-option-class">Grand Total Position:</div> <select value={this.state.grandTotalPosition} name="grandTotalPosition" id="grandTotalPosition" class="grandTotalPosition select-option-select" onChange={this.handleInputChange}> <option value="0">none</option> <option value="1">row</option> <option value="2">col</option> <option value="3">both</option> </select> </div> <div> <div class="select-option-class">Subtotals Position:</div> <select value={this.state.subtotalsPosition} name="subtotalsPosition" id="subtotalsPosition" class="subtotalsPosition select-option-select" onChange={this.handleInputChange}> <option value="2">bottom</option> <option value="0">none</option> <option value="1">top</option> </select> </div> <div> <div class="select-option-class">Display Fields In Page Filter Area:</div> <select value={this.state.displayFieldsInPageFilterArea} name="displayFieldsInPageFilterArea" id="displayFieldsInPageFilterArea" class="displayFieldsInPageFilterArea select-option-select" onChange={this.handleInputChange}> <option value="1">overThenDown</option> <option value="0">downThenOver</option> </select> </div> <div> <div class="select-option-class">PivotTable Layout:</div> <select id="pivotTableLayout" class="pivotTableLayout select-option-select" name="pivotTableLayout" value={this.state.pivotTableLayout} onChange={this.handleInputChange}> <option value="0">Compact</option> <option value="1">Outline</option> <option value="2">Tabular</option> </select> </div> <div> <div class="select-option-class">Show Empty Value In Content Area As:</div> <input type="text" name="missingCaption" id="missingCaption" class="missingCaption select-option-select" value={this.state.missingCaption} onChange={this.handleInputChange} /> </div> <div> <div class="select-option-class">Set Row Label Indent In Compact Layout:</div> <input type="number" name="rowLabelIndent" id="rowLabelIndent" class="rowLabelIndent select-option-select" value={this.state.rowLabelIndent} onChange={this.handleInputChange} /> </div> <div> <label for="reportFilterFieldsPerColumn">Report Filter Fields Per Column:</label> <input type="number" name="reportFilterFieldsPerColumn" id="reportFilterFieldsPerColumn" min="1" value={this.state.reportFilterFieldsPerColumn} onChange={this.handleInputChange}></input> </div> {this.state.renderChild ? <input type="button" value="Apply" class="set-option" id="set-option" onClick={this.handleSetOption}></input> : ""} </div> </div> ); } initSpread(spread) { spread.suspendPaint(); spread.setSheetCount(2); let sheet1 = spread.getSheet(0); let sheet2 = spread.getSheet(1); let tableName = this.getDataSource(sheet2, pivotSales); let pivotTable = this.initPivotTable(sheet1, tableName); this.pivotTable = pivotTable; spread.resumePaint(); } componentDidMount() { this.setState(() => ({ renderChild: true })) } 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(); } initPivotTable(sheet, source) { sheet.name("PivotTable"); sheet.setRowCount(1000); let option = { bandRows: true, bandColumns: true }; let pivotTable = sheet.pivotTables.add("pivotTable", source, 1, 1, GC.Spread.Pivot.PivotTableLayoutType.outline, GC.Spread.Pivot.PivotTableThemes.medium8, option); pivotTable.suspendLayout(); pivotTable.add("quantity", "Quantity", GC.Spread.Pivot.PivotTableFieldType.filterField); pivotTable.add("price", "Price", GC.Spread.Pivot.PivotTableFieldType.filterField); pivotTable.add("salesperson", "Salesperson", GC.Spread.Pivot.PivotTableFieldType.rowField); pivotTable.add("car", "Cars", GC.Spread.Pivot.PivotTableFieldType.rowField); let groupInfo = { originFieldName: "date", dateGroups: [{ by: GC.Pivot.DateGroupType.quarters }] }; pivotTable.group(groupInfo); pivotTable.add("분기 (date)", "분기 (date)", GC.Spread.Pivot.PivotTableFieldType.columnField); 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$/ko/react/node_modules/@mescius/spread-sheets/styles/gc.spread.sheets.excel2013white.css"> <script src="$DEMOROOT$/spread/source/data/pivot-data.js" type="text/javascript"></script> <!-- SystemJS --> <script src="$DEMOROOT$/ko/react/node_modules/systemjs/dist/system.src.js"></script> <script src="systemjs.config.js"></script> <script> System.import('$DEMOROOT$/ko/lib/react/license.js').then(function () { System.import('./src/app'); }); </script> </head> <body> <div id="app" style="height: 100%;"></div> </body> </html>
.sample-tutorial { position: relative; height: 100%; overflow: hidden; } .sample-spreadsheets { width: calc(100% - 300px); height: 100%; overflow: hidden; float: left; } .options-container { float: right; width: 300px; padding: 12px; height: 100%; box-sizing: border-box; background: #fbfbfb; overflow: auto; } body { position: absolute; top: 0; bottom: 0; left: 0; right: 0; } .set-option { display: block; margin-top: 20px; width: 250px; } #reportFilterFieldsPerColumn { width: 28px; } .select-option-class{ display: block; margin-top: 20px; margin-bottom: 10px } .select-option-select{ width: 250px; display: block; margin-bottom: 20px; } .option-item{ height: 20px; margin-bottom: 10px; }
(function (global) { System.config({ transpiler: 'plugin-babel', babelOptions: { es2015: true, react: true }, meta: { '*.css': { loader: 'css' } }, paths: { // paths serve as alias 'npm:': 'node_modules/' }, // map tells the System loader where to look for things map: { '@mescius/spread-sheets': 'npm:@mescius/spread-sheets/index.js', '@mescius/spread-sheets-resources-ko': 'npm:@mescius/spread-sheets-resources-ko/index.js', '@mescius/spread-sheets-shapes': 'npm:@mescius/spread-sheets-shapes/index.js', '@mescius/spread-sheets-pivot-addon': 'npm:@mescius/spread-sheets-pivot-addon/index.js', '@mescius/spread-sheets-react': 'npm:@mescius/spread-sheets-react/index.js', '@grapecity/jsob-test-dependency-package/react-components': 'npm:@grapecity/jsob-test-dependency-package/react-components/index.js', 'react': 'npm:react/umd/react.production.min.js', 'react-dom': 'npm:react-dom/umd/react-dom.production.min.js', 'css': 'npm:systemjs-plugin-css/css.js', 'plugin-babel': 'npm:systemjs-plugin-babel/plugin-babel.js', 'systemjs-babel-build':'npm:systemjs-plugin-babel/systemjs-babel-browser.js' }, // packages tells the System loader how to load when no filename and/or no extension packages: { src: { defaultExtension: 'jsx' }, "node_modules": { defaultExtension: 'js' }, } }); })(this);