Parameter & ParameterUI

In some conditions, you may use a dynamic parameter instead of a static value to regenerate data in a filter.

SpreadJS supports the parameter and parameterUI to help you accomplish this requirement. Try changing the parameters in the below demo to filter the values.

Description
app.vue
index.html
Copy to CodeMine
Open the demo in new window can open the designer

How to open desgnr

The Parameter interface is as follows:

interface IParameter {
    [parameterName: string]: string | number | boolean | Date;
}
class ReportSheet {
    function setParametersUI(host: HTMLElement | string, initParametersUI: GC.Spread.Report.InitParametersUIFunctionType, onChange: GC.Spread.Report.OnChangeFunctionType): void;
}

type InitParametersUIFunctionType = (sheet: Worksheet) => void;

type OnChangeFunctionType = (sheet: ReportSheet, changedArgs: IParameterChangedArgs) => void;

interface IParameterChangedArgs {
    tag: string; // changed cell bindingPath or tag.
    oldValue: string | number | boolean | Date;
    newValue: string | number | boolean | Date;
}

Right now, the parameter can only be used in a filter.

  1. Define a parameter for a reportSheet:
    const spread = new GC.Spread.Sheets.Workbook('ss', { sheetCount: 1 });
    const ordersTable = spread.dataManager().addTable('Orders', {
        remote: {
            read: {
                url: baseApiUrl + '/Order'
            }
        }
    });
    ordersTable.fetch().then(() => {
        const reportSheet = spread.addSheetTab(0, 'report1', GC.Spread.Sheets.SheetType.reportSheet);
        reportSheet.parameter({
            customerId: "VINET",
            startDate: new Date("1996/7/1"),
            endDate: new Date("1998/7/1"),
        });
    });
  1. Use a parameter in a template cell filter condition:
    const reportSheet = spread.getActiveSheetTab();
    const templateSheet = reportSheet.getTemplate();
    // set value and binding for the template
    templateSheet.setTemplateCell(1, 0, {
        type: 'List',
        binding: `Orders[orderId]`,
        filter: {
            condition: {
                and: [
                    {
                        column: "customerId",
                        operator: "Equal",
                        parameter: "customerId", // use parameter in filter condition.
                    },
                    {
                        column: "orderDate",
                        operator: "GreaterThanOrEqual",
                        parameter: "startDate",
                    },
                    {
                        column: "orderDate",
                        operator: "lessThanOrEqual",
                        parameter: "endDate"
                    }
                ]
            }
        }
    });
    // refresh the report
    reportSheet.refresh();
    // if users want to update the parameter.
    reportSheet.parameter({
        customerId: "TOMSP",
        startDate: new Date("1996/7/1"),
        endDate: new Date("1998/7/1"),
    });
    reportSheet.refresh();
  1. Initialize the parameterUI (Optional):
    var reportSheet = spread.getActiveSheetTab();
    var parameterUIHost = document.getElementById("report-sheet-parameter-ui");
    reportSheet.setParametersUI(parameterUIHost, initParametersUI, parameterOnChanged);

    function initParametersUI (sheet) { // the parameterUI sheet init callback
        sheet.suspendPaint();
        sheet.suspendEvent();
        sheet.getCell(-1, -1).backColor("rgb(225, 225, 225)");
        sheet.setColumnWidth(0, 5);
        sheet.setColumnWidth(1, 220);
        sheet.setColumnWidth(2, 10);
        sheet.setColumnWidth(3, 220);
        sheet.setColumnWidth(4, 10);
        sheet.setColumnWidth(5, 220);
        sheet.setColumnWidth(6, 10);
        sheet.setColumnWidth(7, 105);
        sheet.setRowHeight(0, 10);
        sheet.setRowHeight(1, 30);
        sheet.setRowHeight(2, 30);
        sheet.setValue(1, 1, "CustomerID:");
        sheet.setValue(1, 3, "StartDate:");
        sheet.setValue(1, 5, "EndDate:");
        sheet.getCell(2, 1).bindingPath("customerId"); // bind parameter
        sheet.getCell(2, 3).bindingPath("startDate");
        sheet.getCell(2, 5).bindingPath("endDate");

        let submitButton = new GC.Spread.Sheets.CellTypes.Button(); // add submit button
        submitButton.text("Submit");
        submitButton.buttonBackColor("#00897B");
        submitButton.buttonClickColor("#004D40");
        sheet.getCell(2, 7).tag("submitButton").foreColor("white").cellType(submitButton);
        let style = sheet.getStyle(2, 7);
        style.hAlign = HorizontalAlign.center;
        style.vAlign = VerticalAlign.center;
        style.textIndent = 0;
        sheet.setStyle(2, 7, style);

        sheet.resumeEvent();
        sheet.resumePaint();
    };
    function parameterOnChanged (reportSheet, valueChangedArgs) { // the parameterUI changed callback
        if (valueChangedArgs.tag === "submitButton") { // judge the changed parameter.
            reportSheet.regenerateReport();
        }
    }
Open the demo in new window can open the designer The Parameter interface is as follows: Right now, the parameter can only be used in a filter. Define a parameter for a reportSheet: Use a parameter in a template cell filter condition: Initialize the parameterUI (Optional):
<template> <div class="demo-host"> <div ref="parameterRef" class="parameter-ui"></div> <gc-spread-sheets-designer class="demo-designer" v-if="showDesigner" @designerInitialized="initDesigner" /> <gc-spread-sheets class="demo-runtime" v-else @workbookInitialized="initSpread" /> </div> </template> <script setup> import GC from '@mescius/spread-sheets'; import '@mescius/spread-sheets-print'; import '@mescius/spread-sheets-shapes'; import '@mescius/spread-sheets-charts'; import '@mescius/spread-sheets-reportsheet-addon'; import '@mescius/spread-sheets-tablesheet'; import '@mescius/spread-sheets-ganttsheet'; import '@mescius/spread-sheets-formula-panel'; import '@mescius/spread-sheets-vue'; import '@mescius/spread-sheets-designer-resources-en'; import '@mescius/spread-sheets-designer-vue'; import { ref, onMounted } from 'vue'; import '$DEMOROOT$/spread/source/js/react_vue/license.js'; import { registerlic } from '$DEMOROOT$/spread/source/js/designer/react_vue/license.js'; registerlic(GC); const showDesigner = top === window; const spreadRef = ref(null); const parameterRef = ref(null); const designerRef = ref(null); async function initDesigner(designer) { designerRef.value = designer; let parameterUIHost = parameterRef.value; parameterUIHost.style.display = "none"; await initSpread(designer.getWorkbook(), true); designer.refresh(); } onMounted(() => { parameterRef.value; }); async function initSpread(spread, inDesigner) { spreadRef.value = spread; spread.suspendPaint(); spread.setSheetCount(1); const loadingTip = addLoadingTip(); const res = await fetch('$DEMOROOT$/en/sample/features/report-sheet/data-settings/parameter/spread.json'); await spread.fromJSON(await res.json()); if (!inDesigner) { initParameterFilterReportParameterUI(spread.getActiveSheetTab()); } loadingTip.remove(); spread.resumePaint(); } function addLoadingTip() { const div = document.createElement('div'); div.style.position = 'absolute'; div.style.inset = '0'; div.style.display = 'flex'; div.style.alignItems = 'center'; div.style.justifyContent = 'center'; div.style.background = 'white'; div.style.zIndex = '100'; div.textContent = 'Loading data from server ...'; document.body.appendChild(div); return div; } function initParameterFilterReportParameterUI (reportSheet) { let parameterUIHost = parameterRef.value; reportSheet.setParametersUI(parameterUIHost, initParametersUI, parameterOnChanged); } function initParametersUI (sheet) { } function parameterOnChanged (sheet, valueChangedArgs) { if (valueChangedArgs.tag === "submitOnChangeButton") { sheet.regenerateReport(); } } </script> <style scoped> body { position: absolute; top: 0; bottom: 0; left: 0; right: 0; } #app { height: 100%; } .demo-host { width: 100%; height: 100%; overflow: hidden; } .demo-designer { width: 100%; height: 100%; overflow: hidden; } .demo-runtime { width: 100%; height: calc(100% - 100px); overflow: hidden; } .parameter-ui { width: 100%; height: 100px; overflow: hidden; float: left; } </style>
<!DOCTYPE html> <html style="height:100%;font-size:14px;"> <head> <meta charset="utf-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <title>SpreadJS VUE</title> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <link rel="stylesheet" type="text/css" href="$DEMOROOT$/en/vue3/node_modules/@mescius/spread-sheets/styles/gc.spread.sheets.excel2013white.css"> <link rel="stylesheet" type="text/css" href="$DEMOROOT$/en/vue3/node_modules/@mescius/spread-sheets-designer/styles/gc.spread.sheets.designer.min.css"> <script src="$DEMOROOT$/en/vue3/node_modules/systemjs/dist/system.src.js"></script> <script src="./systemjs.config.js"></script> <script src="./compiler.js" type="module"></script> <script> System.import("./src/app.js"); </script> </head> <body> <div id="app"></div> </body> </html>
(function (global) { SystemJS.config({ transpiler: 'plugin-babel', babelOptions: { es2015: true }, paths: { // paths serve as alias 'npm:': 'node_modules/' }, packageConfigPaths: [ './node_modules/*/package.json', "./node_modules/@mescius/*/package.json", "./node_modules/@babel/*/package.json", "./node_modules/@vue/*/package.json" ], map: { 'vue': "npm:vue/dist/vue.esm-browser.js", 'tiny-emitter': 'npm:tiny-emitter/index.js', 'plugin-babel': 'npm:systemjs-plugin-babel/plugin-babel.js', "systemjs-babel-build": "npm:systemjs-plugin-babel/systemjs-babel-browser.js", '@mescius/spread-sheets-designer-resources-en': 'npm:@mescius/spread-sheets-designer-resources-en/index.js', '@mescius/spread-sheets-designer-vue': 'npm:@mescius/spread-sheets-designer-vue/index.js', '@mescius/spread-sheets-designer': 'npm:@mescius/spread-sheets-designer/index.js', '@mescius/spread-excelio': 'npm:@mescius/spread-excelio/index.js', '@mescius/spread-sheets-barcode': 'npm:@mescius/spread-sheets-barcode/index.js', '@mescius/spread-sheets-charts': 'npm:@mescius/spread-sheets-charts/index.js', '@mescius/spread-sheets-languagepackages': 'npm:@mescius/spread-sheets-languagepackages/index.js', '@mescius/spread-sheets-print': 'npm:@mescius/spread-sheets-print/index.js', '@mescius/spread-sheets-pdf': 'npm:@mescius/spread-sheets-pdf/index.js', '@mescius/spread-sheets-shapes': 'npm:@mescius/spread-sheets-shapes/index.js', '@mescius/spread-sheets-io': 'npm:@mescius/spread-sheets-io/index.js', '@mescius/spread-sheets-reportsheet-addon': 'npm:@mescius/spread-sheets-reportsheet-addon/index.js', '@mescius/spread-sheets-tablesheet': 'npm:@mescius/spread-sheets-tablesheet/index.js', '@mescius/spread-sheets-ganttsheet': 'npm:@mescius/spread-sheets-ganttsheet/index.js', '@mescius/spread-sheets-formula-panel': 'npm:@mescius/spread-sheets-formula-panel/index.js', '@mescius/spread-sheets-vue': 'npm:@mescius/spread-sheets-vue/index.js', '@mescius/spread-sheets': 'npm:@mescius/spread-sheets/index.js', }, meta: { '*.css': { loader: 'systemjs-plugin-css' }, '*.vue': { loader: "../plugin-vue/index.js" } } }); })(this);