空白値の表示

テーブルシートでは、列内の null 値や空値の表示方法をカスタマイズするために、showNullAs オプションと showEmptyAs オプションを提供しています。

showNullAs プロパティと showEmptyAs プロパティの説明は次のとおりです。 showNullAs: セル値が null または undefined の場合にカスタムテキストを表示します showEmptyAs: セル値が空文字列 "" の場合にカスタムテキストを表示します これらのオプションは、IColumn で ビューの列定義 または テーブルスキーマの列定義 に設定できます。
/*REPLACE_MARKER*/ /*DO NOT DELETE THESE COMMENTS*/ window.onload = function() { var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"), { sheetCount: 0 }); initSpread(spread); }; function initSpread(spread) { spread.suspendPaint(); var dataManager = spread.dataManager(); // null値や空の値を含むサンプルデータ var sampleData = [ { Id: 1, Name: "John Doe", Email: "john@example.com", Phone: "123-456-7890", Score: 85, JoinDate: "2023-01-15", Notes: "Regular customer" }, { Id: 2, Name: "Mike Johnson", Email: "", Phone: "234-567-8901", Score: null, JoinDate: null, Notes: null }, { Id: 3, Name: "Jane Smith", Email: null, Phone: "", Score: 92, JoinDate: "2023-06-20", Notes: "" }, { Id: 4, Name: "Sarah Connor", Email: "jane@example.com", Phone: null, Score: 78, JoinDate: null, Notes: "VIP member" }, { Id: 5, Name: "Bob Wilson", Email: "", Phone: null, Score: null, JoinDate: "2024-03-10", Notes: "" }, { Id: 6, Name: "Alice Brown", Email: "alice@example.com", Phone: "345-678-9012", Score: 88, JoinDate: null, Notes: "New member" }, { Id: 7, Name: "Tom Harris", Email: "tom@example.com", Phone: null, Score: 95, JoinDate: "2024-07-05", Notes: null }, { Id: 8, Name: "Charlie Davis", Email: "", Phone: "456-789-0123", Score: null, JoinDate: null, Notes: "" }, { Id: 9, Name: "Diana Prince", Email: null, Phone: "567-890-1234", Score: 72, JoinDate: "2024-12-01", Notes: "Premium user" }, { Id: 10, Name: "Eva Green", Email: "eva@example.com", Phone: "", Score: null, JoinDate: null, Notes: null }, ]; // アプローチ1: テーブルスキーマレベルでの設定 (Name, Email, Score) var myTable = dataManager.addTable("myTable", { data: sampleData, schema: { columns: { Id: { dataType: "number" }, Name: { showNullAs: "[NULL]", showEmptyAs: "[EMPTY]" }, Email: { showNullAs: "[NULL]", showEmptyAs: "[EMPTY]" }, Score: { showNullAs: "0", dataType: "number" }, JoinDate: { showNullAs: "[NO DATE]", dataType: "date" } // PhoneとNotesはスキーマレベルでは設定されていません。ビューレベルで設定します } } }); var sheet = spread.addSheetTab(0, "BlankValueDemo", GC.Spread.Sheets.SheetType.tableSheet); // アプローチ2: ビューレベルでの設定 (Phone, Notes) var myView = myTable.addView("myView", [ { value: "Id", caption: "ID", width: 60 }, { value: "Name", caption: "Name", width: 150 }, { value: "Email", caption: "Email", width: 200 }, // ビューレベルでのPhoneとNotesの設定 { value: "Phone", caption: "Phone", width: 130, showNullAs: "[NO PHONE]", showEmptyAs: "[BLANK]" }, { value: "Score", caption: "Score", width: 80, style: { hAlign: "right" } }, { value: "JoinDate", caption: "Join Date", width: 150, style: { hAlign: "right", formatter: "M/d/yy" } }, { value: "Notes", caption: "Notes", width: 180, showNullAs: "[NULL]", showEmptyAs: "[NO NOTES]" } ]); myView.fetch().then(function() { sheet.setDataView(myView); }); spread.resumePaint(); }
<!doctype html> <html style="height:100%;font-size:14px;"> <head> <meta name="spreadjs culture" content="ja-jp" /> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <link rel="stylesheet" type="text/css" href="$DEMOROOT$/ja/purejs/node_modules/@mescius/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$/ja/purejs/node_modules/@mescius/spread-sheets/dist/gc.spread.sheets.all.min.js" type="text/javascript"></script> <script src="$DEMOROOT$/ja/purejs/node_modules/@mescius/spread-sheets-tablesheet/dist/gc.spread.sheets.tablesheet.min.js" type="text/javascript"></script> <script src="$DEMOROOT$/ja/purejs/node_modules/@mescius/spread-sheets-resources-ja/dist/gc.spread.sheets.resources.ja.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; } .sample-spreadsheets { width: 100%; height: 100%; overflow: hidden; float: left; }