EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: can2pic on May 24, 2013, 09:14:14 AM



Title: Datagrid dynamically change background-color or image of 1 specific cell
Post by: can2pic on May 24, 2013, 09:14:14 AM
Hi,

I need to dynamically change just 1 cells background-color within my datagrid, I have used the example below and this works.I removed the if(value) but then the entire column changed colour.

<script type="text/javascript"> 
        function cellStyler(value,row,index){ 
            if (value < 30){ 
                return 'background-color:#ffee00;color:red;'; 
            } 
        } 
    </script> 


what I am looking to do is replace my original methods:

document.getElementById('mycell1').innerHTML = "<image src='images/triangle_amber_big.png' />";

document.getElementById("mycell2").style.backgroundColor = "#f6ced8"; /*red*/

Any help appreciated,

 Thanks.


Title: Re: Datagrid dynamically change background-color or image of 1 specific cell
Post by: stworthy on May 25, 2013, 02:09:30 AM
To change the cell style, a possible solution is to change the column 'styler' definition and then call 'refreshRow' method to refresh specified row.
Code:
var dg = $('#dg');
var col = dg.datagrid('getColumnOption','listprice');
col.styler = function(){
return 'background-color:#f6ced8';
};
dg.datagrid('refreshRow',index);