Set the NoRecords Template from Controller

Environment

Product Grid for ProgressĀ® TelerikĀ® UI for ASP.NET Core
Product Version 2019.1.220

Description

How can I set the NoRecords Template message to content from the controller?

Solution

Using a Kendo UI Template, pass the text using the controller's ViewData. Then, configure the Kendo UI Grid's NoRecords TemplateID with the ID of the Kendo UI Template.

<style>
    .mystyle {
        color: red;
        font-size: 26px;
    }
</style>
<div>
    @(Html.Kendo().Grid<NoRecordsExample.Models.OrderViewModel>()
        .Name("grid")
        .Columns(columns =>
        {
            columns.Bound(p => p.OrderID).Filterable(false);
            columns.Bound(p => p.Freight);
            columns.Bound(p => p.OrderDate).Format("{0:MM/dd/yyyy}");
            columns.Bound(p => p.ShipName);
            columns.Bound(p => p.ShipCity);
        })
        .Pageable()
        .NoRecords(e => e.TemplateId("myTemplate"))
        .Sortable()
        .Scrollable()
        .Filterable()
        .HtmlAttributes(new { style = "height:550px;" })
        .DataSource(dataSource => dataSource
            .Ajax()
            .PageSize(20)
            .Read(read => read.Action("Orders_Read", "Grid"))
        )
    )
</div>

<script type="text/x-kendo-template" id="myTemplate">
    <div class="mystyle">@ViewData["NoRecords"]</div>
</script>
public class HomeController : Controller
{
    public IActionResult Index()
    {
        ViewData["NoRecords"] = "Custom No Data Message";
        return View();
    }
}

See Also

In this article
Not finding the help you need? Improve this article