When using TypeScript, you must define a type for your extraProps if you want to fully leverage the APIs (coloring, selection, navigation, imputation, etc.).
type CellStatus = {
status: 'active' | 'inactive' | 'unknown';
};
let myExtraProps: CellStatus[][];
let smartSheetRef: SmartSheet<CellStatus>;
...
<SmartSheet
bind:this={smartSheetRef}
...
extraPropsMatrix={myExtraProps}
/>
function colorizeByStatus() {
if (!smartSheetRef) return; // safety check
smartSheetRef.applyBackgroundStyles((cells) => {
const out: [GridPosition, any][] = [];
for (const cell of cells.values()) {
const cellStatus = cell.extraProps.status;
let color;
if (!cellStatus) {
color = undefined;
} else if (cellStatus === 'active') {
color = 'green';
} else if (cellStatus === 'inactive'){
color = 'red';
} else {
color = 'lightblue'
}
out.push([cell.position, { 'background-color': color }]);
}
return out;
});
}