I have created a fairly simple data collection containing about 1500 rows and connected a table element to it on my website. The table shows about 20 rows at a time (not paginated).
I have it coded so that when a user double clicks on any row in the table, certain information in one of the columns in that row is displayed in a pop-up (using a Lightbox).
However my problem is that as soon as the user clicks on a row, the table instantly scrolls to the top.
So, for example, if the user scrolls to row 800 and clicks on it, the table immediately scrolls to the top. The “rowSelect” and “onDblClick” functions still work fine, it’s just the automatic scrolling to the top that is annoying. I would like the table view to remain where it is.
How do I prevent this from happening?
I tried using the table selectRow() method to try to automatically scroll back to the user selected row, but I get the following error: Wix code SDK error: The value of rowIndex parameter that is passed to the selectRow method cannot be set to the value “241”. It must be between 0 and 199.
It looks like it can onlya accept between 0 and 199 as input? Why would the limit be so low?
My rowSelect function is pasted below.
Any help would be appreciated!
Thanks in advance!
export function table1_rowSelect(event) {
// Get the row index of the row selected by the user in table1
table1RowIndex = event.rowIndex;
// Extract the song title and lyrics from the selected row
userSelectedTitle = event.rowData.title;
userSelectedLyrics = event.rowData.body;
// Trigger filtering of table2 (Singers table)
filter2(singerName);
// Ensure the row selected by the user is still highlighted
$w("#table1").selectRow(table1RowIndex);
}
If this doesn’t work and your table has no overflow, you might also try getting the current Y scroll using wixWindow.getBoundingRect and returning to it immediately instead.
Hi David, I’m running into this same problem. I have tried using event.preventDefault() as described above, but I get the error “Property ‘preventDefault’ does not exist on type ‘TableRowEvent’.”
I also tried to figure out how to use your alternative solution with wixWindow.getBoundingRect but I don’t see any info about how to get the current y position of the table, just the y position of the page as a whole.
Lastly, I tried the following but on the scrollTo line I got the error “Expected 0 arguments, but got 1.”