We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

When i change the cell background color the cell does not highlight when the mouse hovers over it

i am using the querycellinfo clientsideevent to change the background color of a cell to red

ie
 function querycellinfo(args) {
args.cell.style.backgroundcolor = "red";
}

however when i do that the cell does not highlight when the mouse hovers over it.
how can i change the background color without losing the css for the mouse hover.
or change the css for the cell back to the default values for the mouse hover

thanks
andrew


1 Reply

SA Saravanan Arunachalam Syncfusion Team March 14, 2017 12:20 PM UTC

Hi Andrew, 
Thanks for contacting Syncfusion’s support. 
We understood from your query, you need to toggle the hover style on the customized cell (by queryCellInfo event) when mouse hovering on the Grid’s rows and we have achieved it by using dataBound event of ejGrid control. In dataBound event, we have bound the jQuery’s mouseenter and mouseleave event to cell elements in the Grid for toggle the hover css on customized cell. Please refer to the below code example and jsplayground sample. 
[CSS]    
<style> 
        .red{ 
            background-color: red; 
        } 
    </style> 
     
[JS]         
            $("#Grid").ejGrid({ 
                dataSource: data, 
                allowPaging: true, 
                queryCellInfo: function(args){ 
                    var val = ej.getObject("Freight", args.data); 
                    if(args.column.field == "Freight" && val>50 && val<100) 
                       $(args.cell).addClass("red"); //Change the background color of cell 
                }, 
                dataBound: function(args){ 
                    var proxy = this; 
                    this.getContent().find("tr td").on("mouseenter mouseleave", function(e){ 
                        ele = $(e.target).closest("tr").find("td.red"); 
                        if(e.type == "mouseenter") 
                            ele.removeClass("red").addClass("normal"); //remove red and add normal class when hover mouse                      
                    })                 
                    this.getContent().find("tr td").on("mouseleave", function(e){  
                         ele = $(e.target).closest("tr").find("td.normal"); 
                         if(e.type == "mouseleave") 
                            ele.addClass("red").removeClass("normal"); //remove normal and add red class when leave mouse   
                    })                      
                }, 
                . . . 
        }) 
        
 
 
Regards, 
Saravanan A. 


Loader.
Live Chat Icon For mobile
Up arrow icon