获取剑道 UI 网格上的行计数

Getting row count on a Kendo UI Grid

本文关键字:网格 UI 获取      更新时间:2023-09-26

我在 kedno 标签条的第二个选项卡中有一个 Kend UI 网格,我需要在其中获取行数。为此,我使用

/**
 * Getting number of rows in grid by it's ID
 * @param {string} gridId ID of the Grid
 * @returns {number} number of rows
 */
function getGridRowsCountById(gridId) {
    var grid = $("#" + gridId).data("kendoGrid");
    console.log(grid);
    grid.dataSource.read();  
    return grid.dataSource.total();    
}

根据 gird 对象的控制台日志,我有嵌套的 dataSource 对象和_total属性,其中包含行数值,但 total() 总是返回 0

试试这个函数:

function getGridRowsCountById(gridId) {
    return $("#" + gridId).data("kendoGrid").dataSource.data().length;
}

避免使用以下划线开头的属性,它很可能用于其他目的。