Lookup Column

When a user marks a column as lookup in the data source schema, the column will be presented as a combo box cell type or a multi-column drop down list in the TableSheet.

Description
app.component.ts
index.html
app.component.html
styles.css
Copy to CodeMine
  1. When a column's lookup is an array in the data source schema, a combo box cell type is set to the column.

This is the sample code of lookup array.

    var workItemTable = dataManager.addTable("WorkItems", {
        data: [
            {
                "ID": 1,
                "Date": "9/12/2020",
                "Description": "Know your numbers",
                "TotalPoints": 10,
                "Type": "Homework"
            },
            //...
        ],
        schema: {
            columns: {
                Date: { dataType: "date" },
                Type: { lookup: ["Homework", "Quiz", "Exam"] }
            }
        }
    });
  1. When the lookup is a relationship name, a multi-column list will be set to the column after the View data is fetched.

This is the sample code of lookup string.

    var studentTable = dataManager.addTable("Students", {
        data: [
            {
                "ID": 1,
                "Name": "Ellen Robinson"
            },
            //...
        ]
    });
    var gradeTable = dataManager.addTable("Grades", {
        data: [
            {
                "StudentID": 1,
                "WorkItemID": 1,
                "Grade": 4
            },
            //...
        ],
        schema: {
            columns: {
                StudentID: {
                    lookup: 'student'
                }
            }
        }
    });
    dataManager.addRelationship(gradeTable, "StudentID", "student", studentTable, "ID", "grades");
  1. When the lookup is an option which contains a relationship name and some columns options, a multi-column list with specified columns will be set to the column.

This is the sample code of lookup options.

    var workItemTable = dataManager.addTable("WorkItems", {
        data: [
            {
                "ID": 1,
                "Date": "9/12/2020",
                "Description": "Know your numbers",
                "TotalPoints": 10,
                "Type": "Homework"
            },
            //...
        ]
    });
    var gradeTable = dataManager.addTable("Grades", {
        data: [
            {
                "StudentID": 1,
                "WorkItemID": 1,
                "Grade": 4
            },
            //...
        ],
        schema: {
            columns: {
                WorkItemID: {
                    // lookup: { name: 'workItem', columns: ["ID", "Description", "TotalPoints", "Type"]}
                    lookup: {
                        name: 'workItem', columns: [
                            { value: "ID" },
                            { value: "Description", width: 150 },
                            { value: "TotalPoints", width: 100 },
                            { value: "Type", width: 150, caption: "WorkItem Type" }
                        ]
                    }
                }
            }
        }
    });
    dataManager.addRelationship(gradeTable, "WorkItemID", "workItem", workItemTable, "ID", "grades");
When a column's lookup is an array in the data source schema, a combo box cell type is set to the column. This is the sample code of lookup array. When the lookup is a relationship name, a multi-column list will be set to the column after the View data is fetched. This is the sample code of lookup string. When the lookup is an option which contains a relationship name and some columns options, a multi-column list with specified columns will be set to the column. This is the sample code of lookup options.
/*REPLACE_MARKER*/ /*DO NOT DELETE THESE COMMENTS*/ 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-tablesheet"; import './styles.css'; @Component({ selector: 'app-component', templateUrl: 'src/app.component.html' }) export class AppComponent { hostStyle = { width: '100%', height: '100%', overflow: 'hidden', float: 'left' }; constructor() { } initSpread($event: any) { let spread = $event.spread; spread.suspendPaint(); spread.clearSheets(); spread.options.autoFitType = GC.Spread.Sheets.AutoFitType.cellWithHeader; var dataManager = spread.dataManager(); // add tables var studentTable = dataManager.addTable("Students", { data: [ { "ID": 1, "Name": "Ellen Robinson" }, { "ID": 2, "Name": "Jerry Williams" }, { "ID": 3, "Name": "Steven Kunes" }, { "ID": 4, "Name": "Lisa Williamsburg" }, { "ID": 5, "Name": "Donald Draglin" } ] }); var workItemTable = dataManager.addTable("WorkItems", { data: [ { "ID": 1, "Date": "9/12/2020", "Description": "Know your numbers", "TotalPoints": 10, "Type": "Homework" }, { "ID": 2, "Date": "10/10/2020", "Description": "Add numbers", "TotalPoints": 10, "Type": "Homework" }, { "ID": 3, "Date": "10/15/2020", "Description": "Addition", "TotalPoints": 25, "Type": "Quiz" }, { "ID": 4, "Date": "11/5/2020", "Description": "Subtract Numbers", "TotalPoints": 10, "Type": "Homework" }, { "ID": 5, "Date": "11/30/2020", "Description": "Subtraction", "TotalPoints": 25, "Type": "Quiz" }, { "ID": 6, "Date": "12/10/2020", "Description": "Mid-term", "TotalPoints": 100, "Type": "Exam" }, { "ID": 7, "Date": "2/2/2020", "Description": "HW 20", "TotalPoints": 10, "Type": "Homework" }, { "ID": 8, "Date": "2/22/2022", "Description": "HW 20", "TotalPoints": 20, "Type": "Homework" } ], schema: { columns: { Date: { dataType: "date" }, Type: { lookup: ["Homework", "Quiz", "Exam"] } } } }); var gradeTable = dataManager.addTable("Grades", { data: [ { "StudentID": 1, "WorkItemID": 1, "Grade": 4 }, { "StudentID": 2, "WorkItemID": 1, "Grade": 9 }, { "StudentID": 3, "WorkItemID": 1, "Grade": 8 }, { "StudentID": 4, "WorkItemID": 1, "Grade": 9 }, { "StudentID": 5, "WorkItemID": 1, "Grade": 6 }, { "StudentID": 1, "WorkItemID": 2, "Grade": 7 }, { "StudentID": 2, "WorkItemID": 2, "Grade": 5 }, { "StudentID": 3, "WorkItemID": 2, "Grade": 7 }, { "StudentID": 4, "WorkItemID": 2, "Grade": 8 }, { "StudentID": 5, "WorkItemID": 2, "Grade": 9 }, { "StudentID": 1, "WorkItemID": 3, "Grade": 18 }, { "StudentID": 2, "WorkItemID": 3, "Grade": 23 }, { "StudentID": 3, "WorkItemID": 3, "Grade": 15 }, { "StudentID": 4, "WorkItemID": 3, "Grade": 19 }, { "StudentID": 5, "WorkItemID": 3, "Grade": 6 }, { "StudentID": 1, "WorkItemID": 4, "Grade": 5 }, { "StudentID": 2, "WorkItemID": 4, "Grade": 8 }, { "StudentID": 3, "WorkItemID": 4, "Grade": 9 }, { "StudentID": 4, "WorkItemID": 4, "Grade": 8 }, { "StudentID": 5, "WorkItemID": 4, "Grade": 6 }, { "StudentID": 1, "WorkItemID": 5, "Grade": 22 }, { "StudentID": 2, "WorkItemID": 5, "Grade": 7 }, { "StudentID": 3, "WorkItemID": 5, "Grade": 12 }, { "StudentID": 4, "WorkItemID": 5, "Grade": 10 }, { "StudentID": 5, "WorkItemID": 5, "Grade": 8 }, { "StudentID": 1, "WorkItemID": 6, "Grade": 45 }, { "StudentID": 2, "WorkItemID": 6, "Grade": 45 }, { "StudentID": 3, "WorkItemID": 6, "Grade": 21 }, { "StudentID": 4, "WorkItemID": 6, "Grade": 86 }, { "StudentID": 5, "WorkItemID": 6, "Grade": 6 } ], schema: { columns: { StudentID: { lookup: 'student' }, WorkItemID: { // lookup: { name: 'workItem', columns: ["ID", "Description", "TotalPoints", "Type"]} lookup: { name: 'workItem', columns: [ { value: "ID" }, { value: "Description", width: 150 }, { value: "TotalPoints", width: 100 }, { value: "Type", width: 150, caption: "WorkItem Type" } ] } } } } }); // add relationships dataManager.addRelationship(gradeTable, "StudentID", "student", studentTable, "ID", "grades"); dataManager.addRelationship(gradeTable, "WorkItemID", "workItem", workItemTable, "ID", "grades"); // add views studentTable.fetch().then(function() { var studentView = studentTable.addView("gradeView", undefined, undefined, { defaultColumnWidth: 120 }); var studentSheet = spread.addSheetTab(0, "Students", GC.Spread.Sheets.SheetType.tableSheet); studentSheet.setDataView(studentView); }); workItemTable.fetch().then(function() { let workItemView = workItemTable.addView("gradeView2", undefined, undefined, { defaultColumnWidth: 150 }); var workItemSheet = spread.addSheetTab(0, "WorkItems", GC.Spread.Sheets.SheetType.tableSheet); workItemSheet.setDataView(workItemView); }); gradeTable.fetch().then(function() { let gradeView = gradeTable.addView("gradesView", [ { caption: "Student ID", value: "StudentID" }, { caption: "Student Name", value: "student.Name", width: 140 }, { caption: "WorkItem ID", value: "WorkItemID" }, { caption: "WorkItem Description", value: "workItem.Description", width: 180 }, { caption: "Grade", value: "Grade" } ], undefined, { defaultColumnWidth: 120 }); var gradeSheet = spread.addSheetTab(0, "Grades", GC.Spread.Sheets.SheetType.tableSheet); gradeSheet.setDataView(gradeView); }); spread.resumePaint(); } } @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$/en/angular/node_modules/@mescius/spread-sheets/styles/gc.spread.sheets.excel2013white.css"> <!-- Polyfills --> <script src="$DEMOROOT$/en/angular/node_modules/core-js/client/shim.min.js"></script> <script src="$DEMOROOT$/en/angular/node_modules/zone.js/fesm2015/zone.min.js"></script> <!-- SystemJS --> <script src="$DEMOROOT$/en/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$/en/lib/angular/license.ts'); System.import('./src/app.component'); }); </script> </head> <body> <app-component></app-component> </body> </html>
<div class="sample-tutorial"> <gc-spread-sheets [hostStyle]="hostStyle" (workbookInitialized)="initSpread($event)"> </gc-spread-sheets> </div>
.sample-tutorial { position: relative; height: 100%; overflow: hidden; } body { position: absolute; top: 0; bottom: 0; left: 0; right: 0; margin: 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-tablesheet': 'npm:@mescius/spread-sheets-tablesheet/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);