ConTeXt: xtables zebra stripe

With natural tables this would have been easy because the environment let you set different values for even and odd rows.

\startsetups [tablebackground]
  \setupTABLE [row] [odd] [background=color,backgroundcolor=gray]
\stopsetups

\starttext

\bTABLE[setups=tablebackground]
\dorecurse{9}{\bTR \expanded{\bTD Row \recurselevel \eTD} \eTR}
\eTABLE

\stoptext

Extreme tables on the other hand don’t support this kind of setup and you have to use the overlay mechanism to create your own backgrounds for the cells.

In the overlay setting you can check the value of the \currentxtablerow counter to apply a different command for odd and even rows.

\startuseMPgraphic {tablebackground}
    fill OverlayBox withcolor \MPcolor{gray} ;
\stopuseMPgraphic

\defineoverlay
  [tablebackground]
  [\ifodd\currentxtablerow
     \useMPgraphic{tablebackground}%
   \fi]

\starttext

\startxtable[background=tablebackground]
\dorecurse{9}{\startxrow \expanded{\startxcell Row \recurselevel \stopxcell} \stopxrow}
\stopxtable

\stoptext

To skip the table header:

\defineoverlay
  [tablebackground]
  [\ifnum\currentxtablerow>1
     \ifodd\currentxtablerow\useMPgraphic{tablebackground}\fi
   \fi]

To apply shading against even rows:

\startuseMPgraphic {tablebackground}
  fill OverlayBox withcolor \MPcolor{gray} ;
\stopuseMPgraphic

\defineoverlay
  [tablebackground]
  [\ifnum\currentxtablerow>1
     \ifodd\currentxtablerow \else
       \useMPgraphic{tablebackground}%
     \fi
   \fi]

\setupxtable[background=tablebackground]

To apply the background against all tables in the document, use:

\setupxtable[background=tablebackground]

Another possibility, based on Wolfgang's answer, is to define a macro that returns a colour suitable for use with the backgroundcolor option of setupxtable. For example:

\definecolor[ColourTertiaryLt][h=a6b6b8]

\def\TableBackgroundColour{%
  \ifnum\currentxtablerow>1
    \ifodd\currentxtablerow\else
      ColourTertiaryLt%
    \fi
  \fi
}

\setupxtable[
  frame=off,
  split=yes,
  header=repeat,
  option={stretch,width},
  framecolor=ColourTertiaryDk,
]
\setupxtable[head][
  topframe=on,
  bottomframe=on,
]
\setupxtable[body][
  background=color,
  backgroundcolor=\TableBackgroundColour,
]
\setupxtable[foot][
  bottomframe=on,
]

This avoids dropping into MetaPost and uses the underlying frame's background colour, which will fill itself nearly perfectly.

To include zebra striping of the footer, move the background setup options for \setupxtable[body] into the first \setupxtable (then \setupxtable[body] can be removed entirely):

\setupxtable[
  frame=off,
  split=yes,
  header=repeat,
  option={stretch,width},
  framecolor=ColourTertiaryDk,
  background=color,
  backgroundcolor=\TableBackgroundColour,
]