FOR ANYONE LOOKING TO COPY THIS CODE … I had to add a line to Bruno’s Accepted answer (very much appreciated!) For some reason javascript returns all results if there is no matching rows.
import wixUsers from "wix-users"
import wixData from "wix-data"
let user = wixUsers.currentUser
let userId = user. id
let isLoggedIn = user. loggedIn
$w.onReady(async () => {
let table = $w("#table1") //Change this to your table element ID.
const filter = await queryDataRelatedUser(userId)
const filterdDataRelatedUser = filter. items
if (filterdDataRelatedUser. length > 0) {
table.rows = filterdDataRelatedUser
} else {
table.rows = null
console.log("No related user found!")
}
})
function queryDataRelatedUser(userId) {
const results = wixData. query("client-records")
.eq("relatedUser", userId)
.find()
return results
}