Since version 0.4 of OS3Grid, the user is able to define and use
styles, a graphical
layout of rows that can be defined by the code. Each row in the table can have its own style and
settings are saved even when the user sorts grid rows.
Styles are a better solution than
set_row_color(), because the latter requires a row number
to be set, while styles are dynamically linked to rows.
By default, OS3Grid provide these styles:
- normal
This is the normal style used to display a row. In OS3Grid, this usually equals to
grey rows.
- note
This style should be used to highlight rows of special importance.
- warn
This style should be used for rows containing data that should be highlighted in a special
way to the user.
- error
If you are using OS3Grid to display a report and there are errors (for example in a log file),
use this style to show errors.
These style are predefined, but this does not limit you with these: you can define your own.
To define a new style, follow the example below, in which we are setting a new style
yellow.
// To set the new style, you have to define "stylename" + 0 and "stylename" + 1
g.cols [ "yellow0" ] = "#f0dc04";
g.cols [ "yellow1" ] = "#fcfc68";
To use a defined (or pre-defined) style inside your grid, you have two choices:
- g.set_style ( style_name )
From this line of code, all rows added will use the defined style.
- g.set_row_style ( style, [ row_num ] )
You can change the style of a specific row, if [row_num] is omitted, the last row inserted
will be affected by this call.