DHTMLX Spreadsheet. Pre-styled cells example
This demo shows how to apply custom cell styles in DHTMLX Spreadsheet using the styles object in the dataset.
Live example
const spreadsheet = new dhx.Spreadsheet("spreadsheet");
const styledDataset = {
data: dataset,
// setting styles for cells
styles: {
someclass: {
background: "#F2F2F2",
color: "#F57C00"
}
}
};
spreadsheet.parse(styledDataset);<!-- component container -->
<div style="height: 100%; max-width:100%" id="spreadsheet"></div>
<!-- dataset -->
<script>
const dataset = [
{ cell: "a1", value: "Ecuador" },
{ cell: "b1", value: "Banana" },
// ... 33 more items (see Live Editor for full data)
];
</script>Visual formatting transforms raw numbers into readable reports. Headers need bold text, financial figures benefit from right alignment, and color coding highlights key metrics. Cell-level styling in the dataset ensures the spreadsheet renders with the intended visual hierarchy from the first frame.
This example defines a styles object with a named style, someclass, that applies background: "#F2F2F2" and color: "#F57C00". Cell objects can reference a named style via the css property, and Spreadsheet applies those styles when spreadsheet.parse(styledDataset) loads the data.
Solution overview
- Define a
stylesmap inside the dataset object:{ someclass: { background: "#F2F2F2", color: "#F57C00" } } - Reference the style on cells with the
cssproperty insidedata - Call
spreadsheet.parse(styledDataset)to render the styled cells
Key points
- Dataset styling: Named styles are declared in the
stylesobject and applied to cells through thecssproperty - Supported properties: Style objects can include properties such as
backgroundandcolor, which are the two properties used in this sample - Parse-time application: The styles take effect when
spreadsheet.parse(styledDataset)loads the dataset
API reference
- parse(): Loads data together with named style definitions.