Can I change the background if a field result is great or equal to another field?

后端 未结 3 495

I am displaying mySQL in an html table.

I would like to change the TD background color of $qty to red IF $qty >= $max or $qty =< $min.

I

3条回答
  •  囚心锁ツ
    2021-01-15 06:49

    I know you have your answer, but it would be better to just write a custom tablesorter widget that highlights the bad quantity table cells. Here is a demo and the code:

    $.tablesorter.addWidget({
        id : "qty",
        format: function(table){
            var i, $td, cur,
                c = table.config,
                cols = c.widgetQty,
                $tr = $(table).children('tbody').children('tr'),
                rows = $tr.length;
            for (i = 0; i < rows; i++){
                $td = $tr.eq(i).find('td');
                cur = parseInt( $td.eq(cols[2]).text(), 10); // current
                if (cur <= parseInt( $td.eq(cols[0]).text(), 10) || // min
                    cur >= parseInt( $td.eq(cols[1]).text(), 10) ){ // max
                    $td.eq(cols[2]).addClass('badqty');
                }
            }
        }
    });
    
    $('table').tablesorter({
        widgets : [ 'zebra', 'qty' ],
        widgetQty : [ 0, 1, 2 ] // min, max, current qty column indexes 
    });​
    

提交回复
热议问题