I have a simple table which I use code as below to populate/refresh a table in (1) page $w.onReady, (2) after add button (add an item) and (3) delete button (Delete an item)
export function tableDisplay(userEmail) {
wixData.query(“DateTimeTest”)
.eq(“title”, userEmail)
.ascending(“dataDateTime”) // this line for sorting
.find()
.then((results) => {
let tableRows = results.items;
$w("#table1").rows = tableRows;
$w("#table1").refresh();
});
}
Problem is, although the row that’s selected in table1_rowSelect matches what the user clicked/selected on the screen, in buttonDelete_click, the row that’s returned from $w(“#dataset1”).getCurrentItem() is sometimes a completely different item.
This causes major problem as user will then delete the wrong item from what’s actually selected.
Suspect it’s because of the sorting which causes the displayed order to be different from the actual order in the database. And if I remove that " .ascending(“dataDateTime”) " line then the $w(“#dataset1”).getCurrentItem() inside buttonDelete_click returns the correct item. But I need the sorting to make the table easy to read.
Any idea how to keep the sorting and also make the $w(“#dataset1”).getCurrentItem() inside buttonDelete_click always returns the same item as what’s selected on the table?