From 7d4e5cb0a98fbc3c397c6c74385210e4ac5b3811 Mon Sep 17 00:00:00 2001 From: Henrik Paul Date: Thu, 20 Nov 2014 12:46:01 +0200 Subject: Adds naïve zebra striping to Grid (#13334) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Ia9a031f87065552688dffe3281bf647582b8f872 --- WebContent/VAADIN/themes/base/grid/grid.scss | 8 ++++++++ client/src/com/vaadin/client/ui/grid/Grid.java | 10 ++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/WebContent/VAADIN/themes/base/grid/grid.scss b/WebContent/VAADIN/themes/base/grid/grid.scss index 69b293e26e..de30424d22 100644 --- a/WebContent/VAADIN/themes/base/grid/grid.scss +++ b/WebContent/VAADIN/themes/base/grid/grid.scss @@ -31,6 +31,14 @@ background: rgb(244,244,244); } } + + .#{$primaryStyleName}-row > td { + background-color: #fff; + } + + .#{$primaryStyleName}-row-stripe > td { + background-color: #eee; + } .#{$primaryStyleName}-row-selected > td { background: lightblue; diff --git a/client/src/com/vaadin/client/ui/grid/Grid.java b/client/src/com/vaadin/client/ui/grid/Grid.java index 7348ae2140..fe2157c7d3 100644 --- a/client/src/com/vaadin/client/ui/grid/Grid.java +++ b/client/src/com/vaadin/client/ui/grid/Grid.java @@ -762,6 +762,7 @@ public class Grid extends ResizeComposite implements private SelectionColumn selectionColumn; + private String rowStripeStyleName; private String rowHasDataStyleName; private String rowSelectedStyleName; private String cellFocusStyleName; @@ -1249,6 +1250,9 @@ public class Grid extends ResizeComposite implements setStyleName(rowElement, rowHasDataStyleName, hasData); } + boolean isEvenIndex = (row.getRow() % 2 == 0); + setStyleName(rowElement, rowStripeStyleName, isEvenIndex); + // Assign stylename for selected rows if (hasData) { setStyleName(rowElement, rowSelectedStyleName, @@ -1578,8 +1582,10 @@ public class Grid extends ResizeComposite implements escalator.setStylePrimaryName(style); editorRow.setStylePrimaryName(style); - rowHasDataStyleName = getStylePrimaryName() + "-row-has-data"; - rowSelectedStyleName = getStylePrimaryName() + "-row-selected"; + String rowStyle = getStylePrimaryName() + "-row"; + rowHasDataStyleName = rowStyle + "-has-data"; + rowSelectedStyleName = rowStyle + "-selected"; + rowStripeStyleName = rowStyle + "-stripe"; /* * TODO rename CSS "active" to "focused" once Valo theme has been -- cgit v1.2.3