styling table row of google table visualization causing issues

642 views
Skip to first unread message

dv

unread,
Jan 28, 2012, 6:28:07 PM1/28/12
to Google Visualization API
Hey all,

I need to custom a table row based on whether the value of one of the
cells is an even or odd number. So after table is created, I add this
line of code:


$('.google-visualization-table-td-number').each(function(){ $
(this).html()%2==0 ? $(this).parent().css('background-color','red !
important') : $(this).parent().css('background-color','blue !
important') });


I inspect in google chrome browser and indeed the background color is
applied to the table row. But it's not actually rendering the color
for the table row in the browser. Thats because whatever value is set
in .google-visualization-table-tr-even and .google-visualization-table-
tr-odd classes is overriding my background style.

So I do this:

$('.google-visualization-table-tr-even').removeClass('google-
visualization-table-tr-even');
$('.google-visualization-table-tr-odd').removeClass('google-
visualization-table-tr-odd');
$('.google-visualization-table-td-number').each(function(){ $
(this).html()%2==0 ? $(this).parent().css('background-color','red !
important') : $(this).parent().css('background-color','blue !
important') });

And it works, the colors display right, but as soon as I hover over
one of rows, the .google-visualization-table-tr-even and .google-
visualization-table-tr-odd classes come back and the backgorund-color
goes away.

Any good way to fix this problem?

thanks for response

Dan Vig

unread,
Jan 29, 2012, 12:52:34 PM1/29/12
to Google Visualization API
So is what I am trying to do not possible?


--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To post to this group, send email to google-visua...@googlegroups.com.
To unsubscribe from this group, send email to google-visualizati...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-visualization-api?hl=en.


asgallant

unread,
Jan 30, 2012, 11:55:42 AM1/30/12
to google-visua...@googlegroups.com
You might try wrapping your code for removing the even/odd class names from the table rows in a hover event listener:

$('.google-visualization-table-td-number').hover(function ({
    $('.google-visualization-table-td-number').each(function({
        $(this).html()%2==$(this).parent().css('background-color','red ! important'$(this).parent().css('background-color','blue ! important');
    });
});

Dan Vig

unread,
Jan 31, 2012, 4:01:47 PM1/31/12
to google-visua...@googlegroups.com
tried it and doesnt work

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.

ChartMan

unread,
Jan 31, 2012, 5:31:22 PM1/31/12
to google-visua...@googlegroups.com
Try first setting the table row class to some custom CSS class using cssClassNames option.
Afterwards, use your hack to color different cells.

HTH
ChartMan
Reply all
Reply to author
Forward
0 new messages