Search code examples
javagwtdatagridcelltable

How to keep odd/even background colors on selection?


I have a GWT DataGrid (CellTable) with different background colors for odd/even rows:

.dataGridEvenRow { background: white !important; }
.dataGridEvenRowCell { border: selectionBorderWidth solid white !important; }
.dataGridOddRow { background: red !important; }
.dataGridOddRowCell { border: selectionBorderWidth solid red !important; }

On selection, I only want to change the border color, but the background should not be changed. But when I'm using styles as follows, the background IS always changed to 'white'.

/* Here something must be wrong */
.dataGridSelectedRow {
  background: inherit !important;
  color: inherit !important;
}

That's the inner background of the cells. But it does not inherit from the odd/even rows, but somehow from somewher else...


Solution

  • I fixed it using the following styles:

    .dataGridSelectedRow {
      color: inherit !important;
    }
    
    .dataGridSelectedRowCell {
      background: inherit;
      border: selectionBorderWidth solid inherit !important;
    }
    

    Important is to not use !important on the background property there. Don't know why, but it only works this way.