angular - 计算 ag-grid 中选定行的数量

标签 angular ag-grid

我想计算所选行的数量,但似乎 onRowClickedonRowSelected 发生在我实际单击的行被选择之前。

当我选择一行时,如何计算行数?我认为这就是要走的路。

this.gridOptions.onRowSelected = function (params) {
    console.log(this.gridOptions.api.getSelectedRows().length) 
    // Prints one less then the number of rows that is selected.
}

最佳答案

在 React(使用 ES6)项目中我使用这个:

onSelectionChanged = debounce((e) => {
    this.setState({
        selectedRows: this.api.getSelectedRows(),
    });
}, 1)

(this.apihttps://www.ag-grid.com/javascript-grid-api/?framework=all#gsc.tab=0 )

我使用Lodash's debounce解决同时选择多行时的性能问题。 (尽管经过一些快速测试,看起来这个问题已经在 ag-grid 中的某个时刻得到了修复。)

最简单的版本可能看起来像(未经测试):

this.gridOptions.onSelectionChanged = function () {
    console.log(this.gridOptions.api.getSelectedRows().length);
}

关于angular - 计算 ag-grid 中选定行的数量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44263350/

相关文章:

angular - 我需要在 CI 作业中缓存什么以避免每次 ngcc 重新编译?

javascript - 有 Angular ;错误: Component NewPharmacyComponent is not part of any NgModule or the module has not been imported into your module

angular - 内容安全策略 : Refused to execute inline script on lite server

javascript - Ag-grid过滤器排序错误

javascript - 如何在kendo网格列模板中调用模态窗口?

javascript - 使用moment JS/angularjs检查时间差是否超过30分钟

ag-grid - 如何从 Ag-Grid 上下文菜单中隐藏 'Export' 并替换为 'Tool Panel '?

Angular Grid Ag-Grid,使列可动态编辑

ag-grid - 将 ag-grid 列绑定(bind)到数组

angular - kendo-numerictextbox' 不是已知元素