Add html attributes to a treegrid cell

Hi,

I would like add a specific html attribute to every cell in the generated HTML.
The attribute has different value for every cell.
Furthermore I need distinguish between header cell and data cell.

I noticed there isn't the cellOnDataBound event on the API.
How can i do?

1 Reply

PE Punniyamoorthi Elangovan Syncfusion Team March 13, 2018 12:14 PM UTC

Hi Guiseppe, 
Your requirement can be achieved by using QueryCellInfo client side event. This event will be triggered for every cell in TreeGrid, and you can set the HTML attribute for the cells within this event.  Please refer the following code snippet. 
<ej:TreeGrid runat="server" ID="TreeGrid" IdMapping="Id" ParentIdMapping="ParentId"  QueryCellInfo="queryCellInfo"  
//.. 
</ej:TreeGrid> 
 
<script type="text/javascript"> 
         function queryCellInfo(args) { 
             if (args.cellValue == 10)  
                 $(args.cellElement).attr('custom', 'test'); 
         } 
 
     </script> 

You can also distinguish between the header cell and data cell with the element’s class name, for the header cell the class name is “e-headercell” and for the data cell the class name will be 
“e-rowcell”. 
Please let us know if you require further assistance on this. 
Regards, 
Punniyamoorthi 


Loader.
Up arrow icon