The description of the showNullAs and showEmptyAs properties as follows:
showNullAs: Display custom text when cell value is null or undefined
showEmptyAs: Display custom text when cell value is empty string ""
These options can be configured in IColumn at View column level or Table schema column level:
/*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();
// Sample data with null and empty values to demonstrate the feature
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 },
];
// APPROACH 1: Configure at Table Schema Level (for 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 and Notes NOT configured at schema level - will configure at view level
}
}
});
var sheet = spread.addSheetTab(0, "BlankValueDemo", GC.Spread.Sheets.SheetType.tableSheet);
// APPROACH 2: Configure at View Level (for 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 },
// View-level configuration for Phone and 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 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/@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$/en/purejs/node_modules/@mescius/spread-sheets/dist/gc.spread.sheets.all.min.js" type="text/javascript"></script>
<script src="$DEMOROOT$/en/purejs/node_modules/@mescius/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;
}
.sample-spreadsheets {
width: 100%;
height: 100%;
overflow: hidden;
float: left;
}