如何在可分组的 kendo 网格中设置空数据文本?

How to set empty data text in a groupable kendo grid?

我有一个groupable kendo grid

请帮我在网格为空时设置一些自定义文本。

如果网格不可分组,我可以使用数据绑定功能实现它。

这是我从 KendoGridBinderEx 改编的版本,因为我想要一个关于数据绑定的函数,它不仅可以处理空情况,还可以处理错误情况。我已将其修改回最适合您所遇到的问题。当我的数据源有错误时,我会从我传递给函数本身的事件中读取它们,这就是为什么您看到 'e' 被引用为参数但未被使用的原因。

function DisplayNoResultsFound(evt) {
    var grid = evt.sender.element;
    //Only do this if you can properly find the grid
    if (grid.data("kendoGrid") == undefined) {
        return;
    }

    // Get the number of Columns in the grid
    var dataSource = grid.data("kendoGrid").dataSource;
    var colCount = grid.find('.k-grid-header colgroup > col').length;

    //Check for an empty datasource
    if (dataSource._view.length == 0) {
        //Clear the grid 
        //you may or may not need this depending on how your datasource returns
        grid.find('.k-grid-content tbody').empty();

        //Add the no result row
        grid.find('.k-grid-content tbody')
        .append('<tr class="kendo-data-row"><td colspan="' + colCount + '" style="text-align:center" class="k-state-error"><b>No Results Found</b></td></tr>');
    }

    // Get visible row count
    var rowCount = grid.find('.k-grid-content tbody tr').length;

    // If the row count is less that the page size add in the number of missing rows
    if (rowCount < dataSource._take) {
        var addRows = dataSource._take - rowCount;
        for (var i = 0; i < addRows; i++) {
            grid.find('.k-grid-content tbody').append('<tr class="kendo-data-row"><td>&nbsp;</td></tr>');
        }
    }
}

编辑:这是 JSFiddle example