Search results

Cell in ASP.NET Core Tree Grid control

30 Nov 2021 / 1 minute to read

Displaying the HTML content

The HTML tags can be displayed in the TreeGrid header and content by enabling the disableHtmlEncode property.

tagHelper
htmlEncode.cs
Copied to clipboard
<ejs-treegrid id="TreeGrid" dataSource="@ViewBag.datasource" height="300" childMapping="Children" treeColumnIndex="1">
    <e-treegrid-columns>
        <e-treegrid-column field="TaskId" headerText="<span> Task ID </span>" disableHtmlEncode="true" textAlign="Right" width="100"></e-treegrid-column>
        <e-treegrid-column field="TaskName" headerText="<span> Task Name </span>" disableHtmlEncode="true" width="190"></e-treegrid-column>
        <e-treegrid-column field="StartDate" headerText="Start Date" textAlign="Right" format="yMd" type="date" width="120"></e-treegrid-column>
        <e-treegrid-column field="Duration" headerText="Duration" textAlign="Right" width="110"></e-treegrid-column>
    </e-treegrid-columns>
</ejs-treegrid>
Copied to clipboard
public IActionResult Index()
{
    var tree = TreeData.GetDefaultData();
    ViewBag.datasource = tree;
    return View();
}

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.

tagHelper
queryCell.cs
Copied to clipboard
<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>
Copied to clipboard
public IActionResult Index()
{
    var tree = TreeData.GetDefaultData();
    ViewBag.datasource = tree;
    return View();
}

Auto wrap

The auto wrap allows the cell content of the treegrid to wrap to the next line when it exceeds the boundary of the cell width. The Cell Content wrapping works based on the position of white space between words. To enable auto wrap, set the allowTextWrap property to true.

Note: When a column width is not specified, then auto wrap of columns will be adjusted with respect to the treegrid’s width.

tagHelper
autoWrap.cs
Copied to clipboard
<ejs-treegrid id="TreeGrid" dataSource="@ViewBag.datasource" allowTextWrap="true" height="300" childMapping="Children" allowPaging="true" treeColumnIndex="1">
    <e-treegrid-columns>
        <e-treegrid-column field="TaskId" headerText="Task ID" textAlign="Right" width="90"></e-treegrid-column>
        <e-treegrid-column field="TaskName" headerText="Task Name" width="75"></e-treegrid-column>
        <e-treegrid-column field="StartDate" headerText=" Start Date" textAlign="Right" format="yMd" type="date" width="90"></e-treegrid-column>
        <e-treegrid-column field="Duration" headerText="Duration" textAlign="Right" width="90"></e-treegrid-column>
        <e-treegrid-column field="Progress" headerText="Progress" textAlign="Right" width="90"></e-treegrid-column>
    </e-treegrid-columns>
</ejs-treegrid>
Copied to clipboard
public IActionResult Index()
{
    var tree = TreeData.GetDefaultData();
    ViewBag.datasource = tree;
    return View();
}

You can refer to our ASP.NET Core Tree Grid feature tour page for its groundbreaking feature representations. You can also explore our ASP.NET Core Tree Grid example ASP.NET Core Tree Grid example to knows how to present and manipulate data.