I have an event script running in the onRowClick event of my table that
Expands the row's subview, if it is closed, and collapses all others
If the clicked row's subview is open, collapses it
The problem I am running into is that when a component in the subview is clicked on, it is treating it as a row click and closing that subview. I could simply change the script to not allow closing the subview by clicking a row, but I'd like to keep this in if possible so that the user does not have to click the small arrow icon every time.
Is there a way to achieve this?
Adding the onRowClick script below if it helps at all (the currentSubviewInd is a custom prop on the table that tracks the index of the currently opened subview).
def runAction(self, event):
self.collapseSubviews()
# check if the clicked row is already open
if (event.rowIndex != self.custom.currentSubviewInd):
self.expandSubviews([event.rowIndex])
self.custom.currentSubviewInd = event.rowIndex
else:
# reset custom prop
self.custom.currentSubviewInd = -1
Make sure that the table property rows.subviewExpansionMode == "single"
EDIT: I reread your question and understand your problem now. I was able to replicate this and am not sure how to fix it.
I modified the onRowClick script to this:
if self.props.selection.selectedRow == self.custom.selected_row_old:
self.collapseSubviews()
else:
self.expandSubviews([self.props.selection.selectedRow])
self.custom.selected_row_old = self.props.selection.selectedRow
Clicking on the subview contents when the row is expanded collapses the subview no matter what I try. Not sure if there's a JS injection hack for this where you could target only the subview div
Expands the row's subview, if it is closed, and collapses all others
Is there a reason you aren't changing the properties to single for subviewExpansionMode to achieve behavior like this? Then you just need the script to expand on row click in addition to the built-in arrow.
Yeah, I realized the table already had the single option for subviewExpansionMode and I was just doing extra work with that earlier. So I removed it, and the script now just a single line calling the expandSubviews() function for the selected row.
That is pretty much where I am stuck at. I'm pretty satisfied with the result as is. Being able to close the subview on a row click is not a necessary thing, just would've been a nice ease-of-use feature for the screen.
Wanted to see if there was some simple fix for it, but I don't want to sink too much time or effort into it.
My bad, the behavior we are looking to avoid is the subview clicking to close, I am not sure how to avoid that I think what you have may be the best solution.