typescript getting value form object array using filter

Viewed 45

I am trying to take the latest value form the getSelectedNodes array. Below code is working but getting output like first time is [5] second time is [5,6].

 const currentIndex = this.gridApi.getSelectedNodes().filter(
        (item: any) => item.rowIndex >= 5).map((count: any) => count.rowIndex);

The above code is working on a click event.

Each click event I need only the current value. No need to keep the old one.

How can we do it in type script?

1 Answers

The getSelectedNodes method will return an unsorted array of selected. It will have no indication of the last selected row due to the fac that multiple rows can be selected with a single click with SHIFT.

Your only way out is tracking the selected rows in each click by saving the precious indexes to an array.

this.gridApi.getSelectedNodes().filter(
        (item: any) => item.rowIndex >= 5 && !lastSelectedArray.includes(item.rowInd3x)).map((count: any) => count.rowIndex)
Related