Background for the questions:
I have the following table setup that shows the records in a collection. The title column is the link to the dynamic page that shows the record.
Whan the “movie title” is clicked, the correct record from a dynamic page is displayed.
I would like to write to a session variable:
- Which title was selected.
- If there is a previous (.hasPrevious) and a next record in the dataset.
Then when the user returns to this page, I’d like to scroll the table results to the previously selected record and highlight it. Here is a mocked-up example:
Questions:
- After a table is populated with records, can a particular row be highlighted with Javascript?
- Can the table rows be scrolled to the desired (in this case, the previously selected record) row?
Getting the hasNext and hasPrevious values
I experimented with adding a click event to the table to get these values and write them to session variables.
export function movieList_click(event, $w) {
let itemObj = $w(“#dataset1”).getCurrentItem();
lastRecTitle = itemObj.title;
lastRecID = itemObj._id;
lastRecIndex = $w(“#dataset1”).getCurrentItemIndex();
hasNext = $w(“#dataset1”).hasNext();
hasPrev = $w(“#dataset1”).hasPrevious();
session.setItem(“lastRecIndex”,lastRecIndex);
session.setItem(“lastRecTitle”,lastRecTitle);
session.setItem(“hasNext”,hasNext);
session.setItem(“hasPrev”,hasPrev);
This seemed to work as long as the table was on the first page. The session variables all contained accurate information.
Then if the table was manually scrolled to any other page by clicking on the arrow above to move to page 2, the movieList_click event would record the corresponding record and values from page 1 of the table, thus an incorrect record.
It is interesting that the correct movie does display on the dynamic page, just the wrong values are recorded in the session variables.
Example:
Using the image above the second record on page 1 is: “127 Hours”. If that record is clicked on, the session variables are correct and 127 Hours displays in the dynamic page.
If the user clicks the arrow at the bottom of the table to advance the table to the second page the next set of movies properly displays. The second record on that page is “Avator”. Then if “Avator” is clicked on, the session variables record the corresponding record from that position on page 1 of the table, which in this example is “127 Hours”. Then the correct movie “Avator” is displayed in the dynamic page.
I’m sure it’s something I’m doing incorrectly. Any ideas?