javascriptdojodojox.grid.datagrid

Event to highlight a cell in enhanced grid


I am using dojo toolkit version 1.10. We have a problem where we need to highlight a particular cell. We can able to highlight a row on onStyleRow. But is there any way to highlight a particular cell in enhanced grid?

EDITED:

For formatter I have made this. This is my formatter -

var cellformatter = function(value){

     color = "green";

     return "<span style=color:green>" + value +"</span>;"
}

And I am binding this to available grid structure I have.

for (var i=0;i<gridStructure.length;i++)
{
    var gridData = gridStructure[i];

    gridData.formatter = cellformatter ;

}

And in grid definition I am adding it to structure. -

var mygrid = new EnhancedGrid({
    id: 'grid',
    store: gridStore, //Data store passed as input
    structure: gridData, //Column structure passed as input
    autoHeight: true,
    autoWidth: true
})

But If I do it data won't show. If I use as a string in formatter value I can see it is coming in alert but if a function is used it is not at all coming. I dont know what is the problem here.

Adding an image

Here you can see an excel sheet row is highlighted but not the first cell of the row. Likewise I want some style to be added to a particular cell. Not to whole row or a column


Solution

  • We can use the onStyleRow event itself here. We just need to know the column number and the row number.

    Here is the code

    dojo.connect(grid, "onStyleRow", function(row){
         var nd = dojo.query('td[idx="1"]'  /* <= put column index here */, row.node)[0];
         if(nd){
                if(nd.innerHTML == 'FALSE' /* <= put cell content here */){
                    nd.style.backgroundColor = "red";
                  }else if(nd.innerHTML == "TRUE"){
                     nd.style.backgroundColor = "green";
                     }
                }
            });