In the last post, I showed how to modify the look and feel of a Dojo Data Grid in XPages by selecting a different dojo theme. In this post, I’ll show how to further customize the UI by adding your own CSS.
Dojo Data Grid Series
Dojo Grids in XPages — All Blog Posts
Default Style
Here’s what the grid looks like by default:
Grid Classes to Target
In order to figure out how to override the styling, we need to understand more about the structure of the grid on the page.
There are a lot of divs and tables that get generated when a grid is rendered. There’s a parent grid div, header and view divs, scrollbox and content divs, and then each grid row is a div and table.
Here’s a list of elements that it uses from the start of the grid down to the first data cell:
div.dojoxGrid > div.dojoxGridMasterView > div.dojoxGridView > div.dojoxGridScrollbox > div.dojoxGridContent > div[role="presentation"] > div.dojoxGridRow > table.dojoxGridRowTable > tbody > tr > td.dojoxGridCell
Every other div.dojoxGridRow also gets the dojoxGridRowOdd class as well.
Font and Row Color
Fortunately, we don’t need to go through all of that to find the classes that we need to customize.
You can change the row color and font by targeting .dojoxGridRow tr
/* Grid Row - Default Styles */ .dojoxGridRow tr { background-color: #2F4F4F; color: #FFFFFF; font-size: 14px; }
Fixing Header/Cell Alignment with Column Widths
Once you start changing default fonts (or padding), it throws off the alignment of the column headers to the column data.
The simplest way to fix this is to define the width of each grid column explicitly in the grid column properties. This ensures that the header and cell line up.
Alternate Row Color
You can also change the alternate row color and font by targeting .dojoxGridRowOdd tr
/* Grid Row -- Alternate Row Background Color*/ .dojoxGridRowOdd tr { background-color: #778899; }
Row Hover
It’s a little trickier, but you can also override the row hover styles. In this case, I’m changing the background color, text color, and font size.
/* Grid Row - Hover Styles */ .dojoxGridRow tr:hover td { background-color: white !important; color: #2F4F4F !important; font-size: 18px; }
Header
You can also modify the style of the column header cells. You have to target both the header cell and the div contained within the header cell in order to fully change the background color, which uses an image by default.
/* Grid Header - Styles */ .dojoxGridHeader .dojoxGridCell { background-image: none !important; background-color: #777777 !important; } .dojoxGridHeader .dojoxGridCell div { color: white; font-size: 12px; }
