How to know which row is expanded in a table?

I am using the '.expandSubviews()' functions so that when the operator clicks anywhere in the row, the subview is displayed.

I would like to know which row is expanded in order to use '.collapseSubviews()'.

Is there any function that returns which rows are expanded in a table?

No, there is no built-in function to determine which rows have their subviews expanded.