タブパネル:プログラムで作成

HTMLマークアップを使用する代わりに、プログラムでタブをTabPanelコントロールに追加できます。タブのコレクションを取得してコレクションを操作するには、tabsプロパティを使用します。この例ではコード内にいくつかのタブを作成し、各タブでFlexGridをホストしています。

import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import './styles.css'; import * as wjNav from '@grapecity/wijmo.nav'; import * as wjGrid from '@grapecity/wijmo.grid'; import * as wjOData from '@grapecity/wijmo.odata'; // document.readyState === 'complete' ? init() : window.onload = init; // function init() { var theTabPanel = new wjNav.TabPanel('#theTabPanel'), url = 'https://services.odata.org/Northwind/Northwind.svc/', headers = 'Employees,Categories,Products,Customers'.split(','); // theTabPanel.tabs.deferUpdate(function () { headers.forEach(function (header) { // create the tab header element var elHeader = document.createElement('a'); elHeader.textContent = header; // create the tab pane element var elPane = document.createElement('div'), elGrid = document.createElement('div'), theGrid = new wjGrid.FlexGrid(elGrid, { isReadOnly: true, itemsSource: new wjOData.ODataCollectionView(url, header, { sortOnServer: false }) }); elPane.appendChild(elGrid); // add the new Tab to the TabPanel theTabPanel.tabs.push(new wjNav.Tab(elHeader, elPane)); }); }); // select the first tab theTabPanel.selectedIndex = 0; } <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>GrapeCity FlexGrid Dynamic Tabs</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- SystemJS --> <script src="node_modules/systemjs/dist/system.src.js"></script> <script src="systemjs.config.js"></script> <script> System.import('./src/app'); </script> </head> <body> <div class="container-fluid"> <div id="theTabPanel"> </div> </div> </body> </html> .wj-tabpane { padding: 12px; } body { margin-bottom: 48pt; } import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import './styles.css'; import wjOdata from '@grapecity/wijmo.odata'; // import { Component, enableProdMode, NgModule } from '@angular/core'; import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; import { BrowserModule } from '@angular/platform-browser'; import { WjNavModule } from '@grapecity/wijmo.angular2.nav'; import { WjGridModule } from '@grapecity/wijmo.angular2.grid'; // @Component({ selector: 'app-component', templateUrl: 'src/app.component.html' }) export class AppComponent { tabsInfo: any[]; // constructor() { this._initTabsInfo(); } private _initTabsInfo() { let headers = 'Employees,Categories,Products,Customers'.split(','), url = 'https://services.odata.org/Northwind/Northwind.svc/'; this.tabsInfo = []; headers.forEach((header) => { this.tabsInfo.push({ header: header, data: new wjOdata.ODataCollectionView(url, header, {sortOnServer: false}), }); }) } } // @NgModule({ imports: [WjNavModule, WjGridModule, BrowserModule], declarations: [AppComponent], providers: [], bootstrap: [AppComponent] }) export class AppModule { } // enableProdMode(); // Bootstrap application with hash style navigation and global services. platformBrowserDynamic().bootstrapModule(AppModule); <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>GrapeCity FlexGrid Dynamic Tabs</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- Polyfills --> <script src="node_modules/core-js/client/shim.min.js"></script> <script src="node_modules/zone.js/dist/zone.min.js"></script> <!-- SystemJS --> <script src="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.set(SystemJS.resolveSync('rxjs/operators'), System.newModule(m.operators)); System.import('./src/app.component'); }); </script> </head> <body> <app-component></app-component> </body> </html> <div class="container-fluid"> <wj-tab-panel #pTabPanel [selectedIndex]="0"> <wj-tab *ngFor="let tab of tabsInfo"> <a>{{tab.header}}</a> <div> <wj-flex-grid [isReadOnly]="true" [itemsSource]="tab.data"> </wj-flex-grid> </div> </wj-tab> </wj-tab-panel> </div> .wj-tabpane { padding: 12px; } body { margin-bottom: 48pt; }