0

I am using AG Grid getSelectedRows() to get the selected rows data. The issue is when i uncheck some columns to hide it using columns tool Panels, the getSelectedRows() it will retrive all the row vlaues, i mean the hidden and the visibles rows valus. my quiestion, is there any way to get visibles Rows data only?

As the below image shows, i need to get only Country, year and date row values instead of getting all columns

     const selectedRows: any = this.gridOptions.api.getSelectedRows();

enter image description here

https://plnkr.co/edit/0wPm6bVrdPwBjIOSqG2L?p=preview

johannchopin
  • 13,720
  • 10
  • 55
  • 101
A.Alshaikhli
  • 387
  • 2
  • 8
  • 18
  • Could you clarify what you need in your output? Are you wanting to simply limit your results to country, year, and date? I'll post an answer, but I'll be happy to work with you and revise it as needed – Damian C Oct 31 '19 at 03:28
  • @shadowfox476 thank you so much for your Help. Actually your below code will work fine if we have a static number of columns. but the problem is that columns are generated dynamically, so I don't know if it is possible Returns all row values of the columns are currently displayed I found something but I don't know if it's the best practice to do that. we use getAllDisplayedColumns() to get all displayed columns name in array then filter it over getSelectedRows(). do you think it is a good solution to do that? Thanks – A.Alshaikhli Nov 03 '19 at 09:34
  • 1
    If that call is there then I would assume it's okay to use it. As a performance tip, see if you can only run that method once, instead of every row. All rows will have the same columns – Damian C Nov 03 '19 at 12:28

1 Answers1

4

Looks like you can use getRenderedNodes() and then use a mapper

this.gridApi.getRenderedNodes().map((row) => {
    return {
        country: row.data.country,
        year: row.data.year,
        date: row.data.date
    };
});
Damian C
  • 2,111
  • 2
  • 15
  • 17