Cells in ASP.NET CORE TreeGrid
11 Aug 20262 minutes to read
Customize cell styles
The appearance of cells can be customized by using the queryCellInfo event. The queryCellInfo event triggers for every cell. In that event handler, you can get QueryCellInfoEventArgs that contains the details of the cell.
<ejs-treegrid id="TreeGrid" dataSource="@ViewBag.datasource" queryCellInfo="customizeCell" height="300" childMapping="Children" treeColumnIndex="1">
<e-treegrid-columns>
<e-treegrid-column field="TaskId" headerText="Task ID" textAlign="Right" width="100"></e-treegrid-column>
<e-treegrid-column field="TaskName" headerText="Task Name" width="190"></e-treegrid-column>
<e-treegrid-column field="Duration" headerText="Duration" textAlign="Right" width="110"></e-treegrid-column>
<e-treegrid-column field="Progress" headerText="Progress" textAlign="Right" width="110"></e-treegrid-column>
</e-treegrid-columns>
</ejs-treegrid>
<script>
function customizeCell(QueryCellInfoEventArgs) {
var args = QueryCellInfoEventArgs;
if (args.column.field === 'Progress' && args.cell.innerHTML > 90 && args.cell.innerHTML <= 100) {
args.cell.setAttribute('style', 'background-color:#336c12;color:white;');
} else if (+args.cell.innerHTML > 20 && args.column.field === 'Progress') {
args.cell.setAttribute('style', 'background-color:#7b2b1d;color:white;');
}
}
</script>public IActionResult Index()
{
var tree = TreeData.GetDefaultData();
ViewBag.datasource = tree;
return View();
}You can refer to our
ASP.NET Core Tree Gridfeature tour page for its groundbreaking feature representations. You can also explore our ASP.NET Core Tree Grid exampleASP.NET Core Tree Grid exampleto knows how to present and manipulate data.