【问题标题】:ag-grid 20 with Angular 6 export functionality具有 Angular 6 导出功能的 ag-grid 20
【发布时间】:2019-12-04 01:50:54
【问题描述】:

需要帮助导出 ag-grid 中的一些记录。

我正在尝试从我的应用程序中的 ag-grid 导出(csv)某些记录。我不能使用行选择。手动选择一些记录并只想导出这些记录。

  const selectedRows = [{name: 'A'}, {name: 'b'}];

   const params = {
    skipHeader: false,
    columnKeys: ['name'],
    fileName: 'Test_' + Date.now()
  };

  this.GridOptions.api.exportDataAsCsv(params);

如何将 selectedRows 传递给 API?

提前致谢!!!

【问题讨论】:

    标签: angular6 ag-grid ag-grid-angular export-csv


    【解决方案1】:

    您可以通过编程方式选择所需的 RouterLinkWithHref,让 ag-grid 导出选定的行,然后在打印后取消选择(如有必要)。

      const selectedRows = [{name: 'A'}, {name: 'b'}];
    
      this.GridOptions.api.forEachNode((node) => {
        // Check to determine if the row should be selected for printing
        // Replace with your logic if necessary
        if (selectedRows.findIndex((x) => x.name === node.data.name)) {
          // select the row
          node.setSelected(true);
        } else {
          // deselect the row
          node.selected(false);
        }
      });
    
       const params = {
        // only selected rows will be exported
        onlySelected: true,
        skipHeader: false,
        columnKeys: ['name'],
        fileName: 'Test_' + Date.now()    
      };
    
      this.GridOptions.api.exportDataAsCsv(params);
    
      // deselect all rows
      this.GridOptions.api.foreachNode((node) => {
          node.setSelected(false);
      });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-12-02
      • 2018-11-27
      • 2019-07-12
      • 2019-03-16
      • 1970-01-01
      • 2021-01-13
      • 2018-11-22
      • 2019-01-15
      相关资源
      最近更新 更多