I am using a dataset and filter which changes based on which row is clicked in a table (which uses a second dataset). Code is something like:
export function SITMembersTable_rowSelect(event) {
//console.log("rowSelect detected");
itemData = event.rowData;
loadFieldsForRow(itemData);
}
export function loadFieldsForRow(itemData) {
$w("#emailAddress").value = itemData.email;
// Filter the purchases history and purchases data sets
$w("#purchasesdataset").setFilter( wixData.filter()
.startsWith("memberEmail",$w("#emailAddress").value)
);
const currentItem = $w("#purchasesdataset").getCurrentItem();
if ( currentItem === null) {
$w("#currentSku").text = "n/a"
$w("#currentLastActivity").text = "n/a";
$w("#currentNextRenewal").text = "n/a"
} else {
$w("#currentSku").text = currentItem.sku
$w("#currentLastActivity").text = mapLastActivity(currentItem.lastActivity);
let renewalDate = new Date(currentItem.expiryTimeMilliseconds);
$w("#currentLastActivity").text = renewalDate.toString();
}
}
The problem I am seeing is that the code evaluating ‘currentItem’ must be executing prior to the dataset being “finalized” with the filter I’ve set, because I’ve tested it when selecting a row that absolutely has purchase data and I still wind up with “n/a” values.
So I am theorizing that the code testing:
(currentItem === null)
is executing before the dataset is “done” filtering.
What I think I need is to know when the dataset is “ready” after all filtering is in place in order to execute that code.
Is there a way to do this? Is there another approach I can use to get what I want?
Essentially, what I want is when a user clicks a row in the “users” table I want the related subscription purchase info held in another collection to show.