Row and Column State Styles

SpreadJS supports different style options for row and column states.

TableSheet supports these states: GC.Spread.Sheets.StatesType.hover GC.Spread.Sheets.StatesType.readonly (only supported in the column direction) GC.Spread.Sheets.StatesType.active GC.Spread.Sheets.StatesType.selected GC.Spread.Sheets.StatesType.dirty (only supported in the row direction) A user could define a style first, and then add a rule to the TableSheet by binding it to the corresponding state: A user could also remove the state rule:
/*REPLACE_MARKER*/ /*DO NOT DELETE THESE COMMENTS*/ var tablesheet; window.onload = function () { var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"), { sheetCount: 0 }); initSpread(spread); }; function initSpread(spread) { spread.suspendPaint(); spread.options.autoFitType = GC.Spread.Sheets.AutoFitType.cellWithHeader; //init a data manager var baseApiUrl = getBaseApiUrl(); var dataManager = spread.dataManager(); //add product table var productTable = dataManager.addTable("productTable", { remote: { read: { url: baseApiUrl + "/Product" } } }); //init a table sheet var sheet = spread.addSheetTab(0, "TableSheet1", GC.Spread.Sheets.SheetType.tableSheet); sheet.options.allowAddNew = false; //hide new row sheet.options.alternatingRowStyles = null; tablesheet = sheet; sheet.actionColumn.options({ visible: false }); //hide action column sheet.setDefaultRowHeight(40, GC.Spread.Sheets.SheetArea.colHeader); //add validator var dv1 = { type: 'list', source: '0,5,10', inputTitle: 'Please choose a number:', inputMessage: '0, 5, 10' }; //bind a view to the table sheet var myView = productTable.addView("myView", [ { value: "Id", caption: "ID" }, { value: "ProductName", caption: "Name", width: 400 }, { value: "ReorderLevel", caption: "ReorderLevel", width: 120, validator: dv1 }, { value: "UnitPrice", caption: "Unit Price", width: 100, readonly: true }, { value: "UnitsInStock", caption: "Units In Stock", width: 100 }, { value: "UnitsOnOrder", caption: "Units On Order", width: 100 } ]); myView.fetch().then(function () { sheet.setDataView(myView); sheet.addRowStateRule(GC.Spread.Sheets.StatesType.hover, hoverStyle); sheet.addColumnStateRule(GC.Spread.Sheets.StatesType.hover, hoverStyle); sheet.addColumnStateRule(GC.Spread.Sheets.StatesType.readonly, readonlyStyle); }); spread.resumePaint(); // Styles var hoverStyle = new GC.Spread.Sheets.Style(); hoverStyle.backColor = 'AliceBlue'; var readonlyStyle = new GC.Spread.Sheets.Style(); readonlyStyle.foreColor = '#ccc'; var selectedStyle = new GC.Spread.Sheets.Style(); selectedStyle.backColor = 'Aquamarine'; var activeStyle = new GC.Spread.Sheets.Style(); activeStyle.backColor = 'DeepSkyBlue'; var dirtyStyle = new GC.Spread.Sheets.Style(); dirtyStyle.backColor = 'Bisque'; var styleDict = { "1": hoverStyle, "4": readonlyStyle, "16": selectedStyle, "32": activeStyle, "64": dirtyStyle } var statesTable = document.getElementById("states-table"); statesTable.addEventListener("click", function (e) { var target = e.target; if (target && target.tagName.toLowerCase() === "input") { var state = GC.Spread.Sheets.StatesType[target.getAttribute("myState")], direction = target.getAttribute("myDirection"); if (direction === 'row') { if (target.checked) { sheet.addRowStateRule(state, styleDict[state]); } else { sheet.removeRowStateRule(state, styleDict[state]); } } else if (direction === 'column') { if (target.checked) { sheet.addColumnStateRule(state, styleDict[state]); } else { sheet.removeColumnStateRule(state, styleDict[state]); } } } }); } 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 class="options-container"> <div class="option-row"><label>Select different options in the table below and see how they affect the TableSheet.</label> </div> <hr> <div class="option-row"> <table id="states-table"> <tr> <td></td> <td>Rows</td> <td>Columns</td> </tr> <tr> <td>Hover</td> <td><input type="checkbox" checked="checked" myState="hover" myDirection="row" /></td> <td><input type="checkbox" checked="checked" myState="hover" myDirection="column" /></td> </tr> <tr> <td>Readonly</td> <td><input type="checkbox" disabled="disabled" myState="readonly" myDirection="row" /></td> <td><input type="checkbox" checked="checked" myState="readonly" myDirection="column" /></td> </tr> <tr> <td>Active</td> <td><input type="checkbox" myState="active" myDirection="row" /></td> <td><input type="checkbox" myState="active" myDirection="column" /></td> </tr> <tr> <td>Selected</td> <td><input type="checkbox" myState="selected" myDirection="row" /></td> <td><input type="checkbox" myState="selected" myDirection="column" /></td> </tr> <tr> <td>Dirty</td> <td><input type="checkbox" myState="dirty" myDirection="row" /></td> <td><input type="checkbox" disabled="disabled" myState="dirty" myDirection="column" /></td> </tr> </table> </div> </div> </div> </html>
.sample-tutorial { position: relative; height: 100%; overflow: hidden; } .sample-spreadsheets { width: calc(100% - 280px); height: 100%; overflow: hidden; float: left; } .options-container { float: right; width: 280px; height: 100%; box-sizing: border-box; background: #fbfbfb; overflow: auto; } .option-row { font-size: 14px; box-sizing: border-box; } body { position: absolute; top: 0; bottom: 0; left: 0; right: 0; } #states-table { width: 100%; border-collapse: collapse; text-align: center; } #states-table td { border: 1px solid grey; }