일반 슬라이서 데이터

GeneralSlicerData는 데이터를 2차원 배열로 처리하는 데 사용됩니다. 하나의 GeneralSlicerData에 여러 개의 슬라이서를 연결할 수 있으며 각 슬라이서는 하나의 데이터 열을 필터링하는 데 사용됩니다. 임의의 슬라이서가 필터링되면 모든 슬라이서는 GeneralSlicerData로부터 통지를 받습니다. 동시에, 모든 슬라이서는 GeneralSlicerData로부터 필터링된 결과를 가져와 자체 UI를 업데이트합니다.

설명
app.component.ts
index.html
app.component.html
styles.css

슬라이서는 다음 단계에 따라 GeneralSlicerData와 함께 작동합니다:

데이터로 새 GeneralSlicerData를 만듭니다.

새 사용자 정의 슬라이서를 만들고 GeneralSlicerData에 연결합니다.

GeneralSlicerData에서 열 데이터를 가져와서 슬라이서 UI를 작성합니다.

UI 이벤트에 응답하고 GeneralSlicerData doFilter 메서드를 호출합니다.

GeneralSlicerData에서 필터링된 결과를 가져와서 슬라이서 UI를 업데이트합니다.

다음 API는 간단한 코드를 작성하는 데 도움이 됩니다:

getData: 지정된 열의 모든 데이터를 가져옵니다.

getExclusiveData: 지정된 열의 독점 데이터(비반복 데이터)를 가져옵니다.

doFilter: 지정된 열 및 독점 데이터 인덱스에 해당하는 데이터를 필터링합니다.

doUnfilter: 지정된 열에 해당하는 데이터의 필터링을 해제합니다.

attachListener: 슬라이서 데이터에 슬라이서를 연결합니다.

detachListener: 슬라이서 데이터에서 슬라이서를 분리합니다.

onFiltered: 슬라이서 데이터가 필터링된 후에 발생합니다.

슬라이서는 다음 단계에 따라 GeneralSlicerData와 함께 작동합니다: 데이터로 새 GeneralSlicerData를 만듭니다. 새 사용자 정의 슬라이서를 만들고 GeneralSlicerData에 연결합니다. GeneralSlicerData에서 열 데이터를 가져와서 슬라이서 UI를 작성합니다. UI 이벤트에 응답하고 GeneralSlicerData doFilter 메서드를 호출합니다. GeneralSlicerData에서 필터링된 결과를 가져와서 슬라이서 UI를 업데이트합니다. 다음 API는 간단한 코드를 작성하는 데 도움이 됩니다: getData: 지정된 열의 모든 데이터를 가져옵니다. getExclusiveData: 지정된 열의 독점 데이터(비반복 데이터)를 가져옵니다. doFilter: 지정된 열 및 독점 데이터 인덱스에 해당하는 데이터를 필터링합니다. doUnfilter: 지정된 열에 해당하는 데이터의 필터링을 해제합니다. attachListener: 슬라이서 데이터에 슬라이서를 연결합니다. detachListener: 슬라이서 데이터에서 슬라이서를 분리합니다. onFiltered: 슬라이서 데이터가 필터링된 후에 발생합니다.
import { Component, NgModule, enableProdMode } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; import { SpreadSheetsModule } from '@mescius/spread-sheets-angular'; import GC from '@mescius/spread-sheets'; import '@mescius/spread-sheets-resources-ko'; GC.Spread.Common.CultureManager.culture("ko-kr"); import './styles.css'; const initFilteredResultList = (columnNames:string[], data:any[]) => { let tableStr = ''; for (let i = 0; i < columnNames.length; i++) { tableStr += "<th>" + columnNames[i] + "</th>"; } for (let i = 0; i < data.length; i++) { tableStr += "<tr>"; for (let j = 0; j < data[i].length; j++) { tableStr += "<td>" + data[i][j] + "</td>"; } tableStr += "</tr>"; } let table = document.createElement('table'); table.border = '1'; table.cellPadding = '0'; table.cellSpacing = '0'; table.innerHTML = tableStr; document.getElementById('ss').appendChild(table); } class CustomSlicer { container: HTMLElement; slicerData: any; columnName: string; constructor(container: HTMLElement) { this.container = container; this.slicerData = null; this.columnName = null; } setData(slicerData: any[], columnName: string) { this.slicerData = slicerData; this.columnName = columnName; // Invoke attachListener method. this.slicerData.attachListener(this); this.onDataLoaded(); } onDataLoaded() { let columnName = this.columnName, exclusiveData = this.slicerData.getExclusiveData(columnName); let domString = '<span>' + this.columnName + ':</span>' + '<br />'; exclusiveData.forEach(function(exclusiveDataItem: string, index: number) { let id = columnName + index + 1; domString += '<input type="checkbox" class="' + columnName + '" value="' + exclusiveDataItem + '" id="' + id + '" style="margin-left:10px;" checked>' + '<label for="' + id + '">' + exclusiveDataItem + '</label>' + '<br />'; }); this.container.innerHTML = domString; let self = this; let elements: HTMLCollectionOf<Element> = document.getElementsByClassName(columnName); for (let _index = 0; _index < elements.length; _index++) { let element = <any>elements[_index] element.onchange = function(e: MouseEvent) { let parent = (<any>e.target).parentNode, items = parent.childNodes, indexes = []; for (let i = 0, length = items.length; i < length; i++) { if (items[i].checked) { let value = items[i].value; if (!isNaN(parseInt(value))) { value = parseInt(value); } indexes.push(exclusiveData.indexOf(value)) } } if (indexes.length === 0) { // Invoke doUnfilter method when all item are not selected. self.slicerData.doUnfilter(self.columnName); } else { // Invoke doFilter method when any item is selected. self.slicerData.doFilter(self.columnName, { exclusiveRowIndexes: indexes }); } } } } onFiltered() { let slicerdata = this.slicerData; let filteredRowIndexs = slicerdata.getFilteredRowIndexes(); let trs = document.getElementsByTagName('tr'); for (let i = 0; i < slicerdata.data.length; i++) { if (filteredRowIndexs.indexOf(i) !== -1) { trs[i + 1].style.display = ''; } else { trs[i + 1].style.display = 'none'; } } } } @Component({ selector: 'app-component', templateUrl: 'src/app.component.html' }) export class AppComponent { ngAfterContentInit(){ let columnNames = ["Name", "Sex", "City", "Birthday"], data = [ ["Bob", "Man", "NewYork", "1968/06/08"], ["Betty", "Woman", "Washington", "1972/07/03"], ["Alice", "Woman", "Atlanta", "1964/03/02"], ["Tom", "Man", "Houston", "1986/12/03"], ["Jenny", "Woman", "Washington", "1956/10/13"], ["Nacy", "Woman", "NewYork", "1989/01/14"], ["John", "Man", "Houston", "1995/01/01"], ["Mark", "Man", "Atlanta", "1965/11/11"], ["Susan", "Woman", "Atlanta", "1983/07/08"] ]; // Build data UI. initFilteredResultList(columnNames, data); // Create GeneralSlicerData. let slicerData = new GC.Spread.Slicers.GeneralSlicerData(data, columnNames); // Create a custom slicer and attach it to dom tree. let slicer1 = new CustomSlicer(document.getElementById('cityContainer')); slicer1.setData(slicerData, 'City'); let slicer2 = new CustomSlicer(document.getElementById('sexContainer')); slicer2.setData(slicerData, 'Sex'); } } @NgModule({ imports: [BrowserModule, SpreadSheetsModule], declarations: [AppComponent], exports: [AppComponent], bootstrap: [AppComponent] }) export class AppModule { } enableProdMode(); // Bootstrap application with hash style navigation and global services. platformBrowserDynamic().bootstrapModule(AppModule);
<!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/angular/node_modules/@mescius/spread-sheets/styles/gc.spread.sheets.excel2013white.css"> <!-- Polyfills --> <script src="$DEMOROOT$/ko/angular/node_modules/core-js/client/shim.min.js"></script> <script src="$DEMOROOT$/ko/angular/node_modules/zone.js/fesm2015/zone.min.js"></script> <!-- SystemJS --> <script src="$DEMOROOT$/ko/angular/node_modules/systemjs/dist/system.js"></script> <script src="systemjs.config.js"></script> <script> // workaround to load 'rxjs/operators' from the rxjs bundle System.import('rxjs').then(function (m) { System.import('@angular/compiler'); System.set(SystemJS.resolveSync('rxjs/operators'), System.newModule(m.operators)); System.import('$DEMOROOT$/ko/lib/angular/license.ts'); System.import('./src/app.component'); }); </script> </head> <body> <app-component></app-component> </body> </html>
<div class="sample-tutorial"> <div id="ss" class="sample-spreadsheets"></div> <div class="options-container"> <div id="info">Use GeneralSlicerData on the left table to filter data by City and Sex columns.</div> <div id="info"><br>Filter data by the third column using the slicer below:</div><br> <div id="cityContainer"></div> <div id="info"><br>Filter data by the second column using the slicer below:</div><br> <div id="sexContainer"></div> </div> </div>
.sample-tutorial { position: relative; height: 100%; overflow: hidden; } .sample-spreadsheets { width: calc(100% - 280px); height: 100%; overflow: auto; float: left; } .options-container { float: right; width: 280px; padding: 12px; height: 100%; box-sizing: border-box; background: #fbfbfb; overflow: auto; } label { display: inline-block; min-width: 90px; margin: 6px 0; } hr { border-color: #fff; opacity: .2; margin: 12px 0; } table th, table td { padding: 4px 8px; } body { position: absolute; top: 0; bottom: 0; left: 0; right: 0; }
(function (global) { System.config({ transpiler: 'ts', typescriptOptions: { tsconfig: true }, meta: { 'typescript': { "exports": "ts" }, '*.css': { loader: 'css' } }, paths: { // paths serve as alias 'npm:': 'node_modules/' }, // map tells the System loader where to look for things map: { 'core-js': 'npm:core-js/client/shim.min.js', 'zone': 'npm:zone.js/fesm2015/zone.min.js', 'rxjs': 'npm:rxjs/dist/bundles/rxjs.umd.min.js', '@angular/core': 'npm:@angular/core/fesm2022', '@angular/common': 'npm:@angular/common/fesm2022/common.mjs', '@angular/compiler': 'npm:@angular/compiler/fesm2022/compiler.mjs', '@angular/platform-browser': 'npm:@angular/platform-browser/fesm2022/platform-browser.mjs', '@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/fesm2022/platform-browser-dynamic.mjs', '@angular/common/http': 'npm:@angular/common/fesm2022/http.mjs', '@angular/router': 'npm:@angular/router/fesm2022/router.mjs', '@angular/forms': 'npm:@angular/forms/fesm2022/forms.mjs', 'jszip': 'npm:jszip/dist/jszip.min.js', 'typescript': 'npm:typescript/lib/typescript.js', 'ts': './plugin.js', 'tslib':'npm:tslib/tslib.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', '@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-angular': 'npm:@mescius/spread-sheets-angular/fesm2020/mescius-spread-sheets-angular.mjs', '@grapecity/jsob-test-dependency-package/react-components': 'npm:@grapecity/jsob-test-dependency-package/react-components/index.js' }, // packages tells the System loader how to load when no filename and/or no extension packages: { src: { defaultExtension: 'ts' }, rxjs: { defaultExtension: 'js' }, "node_modules": { defaultExtension: 'js' }, "node_modules/@angular": { defaultExtension: 'mjs' }, "@mescius/spread-sheets-angular": { defaultExtension: 'mjs' }, '@angular/core': { defaultExtension: 'mjs', main: 'core.mjs' } } }); })(this);