Customize the Empty Record Template in ASP.NET Core TreeGrid

29 Aug 20252 minutes to read

The empty record template feature in the TreeGrid allows you to use custom content such as images, text, or other components, when the TreeGrid doesn’t contain any records to display. This feature replaces the default message of No records to display typically shown in the TreeGrid.

To activate this feature, set the emptyRecordTemplate property of the TreeGrid. The emptyRecordTemplate property expects the HTML element or a function that returns the HTML element.

In the following example, an image and text have been rendered as a template to indicate that the TreeGrid has no data to display.

<ejs-treegrid id="TreeGrid" dataSource="@ViewBag.data" height="273" toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Cancel", "Update" })" emptyRecordTemplate="#emptytemplate" childMapping="Children" treeColumnIndex="1" allowPaging="true">
    <e-treegrid-pagesettings pageSize="7"></e-treegrid-pagesettings>
    <e-treegrid-editSettings allowAdding="true" allowDeleting="true" allowEditing="true"></e-treegrid-editSettings>
    <e-treegrid-columns>
        <e-treegrid-column field="TaskId" headerText="Task ID" isPrimaryKey="true" textAlign="Right" width="95"></e-treegrid-column>
        <e-treegrid-column field="TaskName" headerText="Task Name" width="220"></e-treegrid-column>
        <e-treegrid-column field="StartDate" headerText=" Start Date" textAlign="Right" format="yMd" type="date" width="115"></e-treegrid-column>
        <e-treegrid-column field="Duration" headerText="Duration" textAlign="Right" width="100"></e-treegrid-column>
    </e-treegrid-columns>
</ejs-treegrid>

<script id="emptytemplate" type="text/x-template">
    <div class='emptyRecordTemplate'>
        <img src="@Url.Content("~/image/emptyRecordTemplate.svg")" class="e-emptyRecord" alt="No record">
        <span>There is no data available to display at the moment.</span>
    </div>
</script>

<style>
    .emptyRecordTemplate {
        text-align: center;
    }
    .e-emptyRecord {
        display: block;
        margin: 10px auto;
    }
</style>
public IActionResult Index()
{
    var tree = TreeData.GetFormatData();
    ViewBag.data = tree;
    return View();
}

Empty Record Template TreeGrid