Data Object

The Data Object CellType provides a more convenient way to use the custom data, which type is object.

A Data Object CellType accepts 1 parameter format, a format string, that contains PROPERTY function or dot operator. It decides how to display the cell value which type is object as a string. This is the class definition. This is the sample code.
/*REPLACE_MARKER*/ /*DO NOT DELETE THESE COMMENTS*/ window.onload = function () { var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss")); initSpread(spread); }; function initSpread(spread) { spread.suspendPaint(); var sheet = spread.getActiveSheet(); sheet.setColumnWidth(1, 500); //set a DataObject celltype which uses WEBSERVICE function to provide data sheet.setFormula(1, 1, '=FILTERJSON(WEBSERVICE("https://demodata.grapecity.com/northwind/api/v1/Products/1"))'); var cellType1 = new GC.Spread.Sheets.CellTypes.DataObject('=@.productName & " " & @.unitPrice'); sheet.setCellType(1, 1, cellType1); var baseApiUrl = getBaseApiUrl(); var dataManager = spread.dataManager(); var productTable = dataManager.addTable("productTable", { remote: { read: { url: baseApiUrl + "/Product" } } }); productTable.primaryKey("id"); var supplierTable = dataManager.addTable("supplierTable", { remote: { read: { url: baseApiUrl + "/Supplier" } } }); dataManager.addRelationship(productTable, "SupplierId", "supplier", supplierTable, "Id", "products"); Promise.all([productTable.fetch(), supplierTable.fetch()]).then(function () { spread.suspendPaint(); //set a DataObject celltype which use QUERY function to provide data sheet.setFormula(2, 1, '=QUERY("productTable?Id=1",,true)'); var cellType2 = new GC.Spread.Sheets.CellTypes.DataObject('=IFERROR(@.ProductName & " " & @.UnitPrice, "")'); sheet.setCellType(2, 1, cellType2); spread.resumePaint(); }); spread.resumePaint(); } function getBaseApiUrl() { return window.location.href.match(/http.+spreadjs\/demos\//)[0] + 'server/api'; }
<!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/purejs/node_modules/@grapecity/spread-sheets/styles/gc.spread.sheets.excel2013white.css"> <!-- Promise Polyfill for IE, https://www.npmjs.com/package/promise-polyfill --> <script src="https://cdn.jsdelivr.net/npm/promise-polyfill@8/dist/polyfill.min.js"></script> <script src="$DEMOROOT$/en/purejs/node_modules/@grapecity/spread-sheets/dist/gc.spread.sheets.all.min.js" type="text/javascript"></script> <script src="$DEMOROOT$/en/purejs/node_modules/@grapecity/spread-sheets-tablesheet/dist/gc.spread.sheets.tablesheet.min.js" type="text/javascript"></script> <script src="$DEMOROOT$/spread/source/js/license.js" type="text/javascript"></script> <script src="app.js" type="text/javascript"></script> <link rel="stylesheet" type="text/css" href="styles.css"> </head> <body> <div class="sample-tutorial"> <div id="ss" class="sample-spreadsheets"></div> <div id="optionContainer" class="optionContainer"> </div> </div> </html>
.sample-tutorial { position: relative; height: 100%; overflow: hidden; } body { position: absolute; top: 0; bottom: 0; left: 0; right: 0; margin: 0; } .sample-spreadsheets { width: 100%; height: 100%; overflow: hidden; float: left; }