We cannot get zebra striping to work in jqGrid.
We use altclass and altRows - issue is it appears the ui-widget-content
class from the JQuery UI has a background
setting which is overriding our altclass's background
setting. Any ideas?
Update: Both answers below work. Oleg's is the cleanest solution by far.
For Oleg's solution to work, your altRows class has to be defined after including the JQuery UI CSS class as both the JQuery UI and the custom alt rows class define the background property and the last class defined wins.
here is my solution:
it worked for me and can be used with any ui theme.
I added the following CSS to a supplementary file to style the alternate row and row hover without using additional Javascript:
Per Oleg.. in loadComplete:
And then in the grid definition:
With `myAltRowClass':
jqGrid use jQuery UI class 'ui-priority-secondary' as the default value of the
altclass
parameter. The class are described in jQuery UI documentation asIt is of cause not exactly the description of the zebra striping, but there are not so many standard classes which can be used. Unfortunately even rows having 'ui-priority-secondary' looks not so different from odd rows in the most themes. So to improve visibility one have to define the class
altclass
manually.One of the most native ways to make even rows seen different as the odd rows is the usage of different background color. The problem is that
ui-widget-content
class use an background image defined withbackground
CSS style, so the most native setting ofbackground-color
will not work. To fix the problem one have to do one from the things 1) removeui-widget-content
class 2) usebackground
CSS style instead ofbackground-color
2) usebackground-image:none
together with thebackground-color
style. The simplest way to do this is define your customAltRowClass
asor
and then to use
altRows:true
andaltclass:'myAltRowClass'
parameters of jqGrid.Another way is to do the same without
altRows
andaltclass
parameters:In the case you will has some small disadvantages in hovering or selecting the even lines. The following code works better, but it do the same what
altRows:true
andaltclass:'myAltRowClass'
do:Of cause the background color and other CSS styles attributes which you can set for the even rows are depend from the theme which you use, so if you plan to use ThemeRoller you will have to choose
altclass
for every theme, which you will allow to choose.UPDATED: Just seen that I forgot to include the link to the demo file which demonstrate what I wrote live. The demo is here.