Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

conditional formatting of html table cells

Are there any out of the box solutions to have conditional formatting of HTML tables?

With conditional formatting I am more interested in having different colors as cell background depending on the value (numeric) of that or some other column (in the same table).

Something similar to what we have in excel Conditional Formating -> Color Scales -> Red Yellow Green. I want to implement that in a table that is being dynamically generated via JSP.

Are there any JavaScript/jquery or JSP solutions for this?

like image 855
Salman A. Kagzi Avatar asked Feb 21 '11 14:02

Salman A. Kagzi


1 Answers

http://jsfiddle.net/stofke/Ya68Q/

      $(function() {
            $('tr > td:odd').each(function(index) {
                var scale = [['vPoor', 10], ['poor', 50], ['avg', 250], ['good', 1250], ['vGood', 6250]];
                var score = $(this).text();
                for (var i = 0; i < scale.length; i++) {
                    if (score <= scale[i][1]) {
                        $(this).addClass(scale[i][0]);
                    }
                }
            });
       });
like image 140
Stofke Avatar answered Oct 22 '22 15:10

Stofke