You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何获取AG Grid分页中当前页的起止行号?

获取AG Grid当前页的起止行号

AG Grid没有直接提供获取当前页起止行号的API,但可以通过现有API参数计算得出,具体方法如下:

  • 获取核心参数

    1. 当前页号:通过gridApi.paginationGetCurrentPage()获取,注意该返回值是从0开始的索引
    2. 每页行数:从gridOptions.paginationPageSize获取,或调用gridApi.paginationGetPageSize()
    3. 总行数:使用你提到的gridApi.paginationGetRowCount()
  • 计算起止行号
    基于上述参数,计算逻辑如下:

    • 起始行号:当前页号 * 每页行数 + 1
    • 结束行号:Math.min((当前页号 + 1) * 每页行数, 总行数)(最后一页时取总行数,避免超出范围)
  • 示例代码

// 提取分页相关参数
const currentPage = gridApi.paginationGetCurrentPage();
const pageSize = gridOptions.paginationPageSize;
const totalRows = gridApi.paginationGetRowCount();

// 计算起止行号
const startRow = currentPage * pageSize + 1;
const endRow = Math.min((currentPage + 1) * pageSize, totalRows);

// 输出格式示例:"101 to 200 of 8,618"
console.log(`${startRow} to ${endRow} of ${totalRows.toLocaleString()}`);
  • 注意事项
    • 确保gridOptions.pagination已设置为true,否则分页相关API无法正常调用
    • 若存在动态修改每页行数的场景,需确保使用最新的pageSize值计算

内容的提问来源于stack exchange,提问作者user21476047

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.08 01:37:37