I am trying to display results of a WiXQuery into a table but a blank table is being displayed.
I have followed a number of similar previous posts but with no luck.
Firstly, I am trying to create a table that has 1 column that displays the teams that appear in the datacollection ‘Players’;
export function refreshTeams_click() {
let QUIZID = $w(‘#quizID’).text;
let query = wixData.query(‘Players’)
.eq(‘gameId’, QUIZID);
query.find()
.then(res => {
let TEAMS = (res.items.nickname);
$w(‘#teamsTable’).rows = TEAMS;
});
}
I want the table to display all teams that have the gameId (field name in collection) that appears in the text box ‘quizID’.
I only want to display the team name, (nickname in the Players collection).
Once I am successful with this, I also want to create a 2 column table that displays the team name and score, (score field name), which does not display all the other column that are in the collection.
Please help : )
Hi Eaton,
In your code, res.items is an array of items. You would set the table like this:
let items = res.items;
$w('#teamsTable').rows = items;
You then need to define a column called Teams, and connect that column to the nickname field in the collection.
You might want to consider using a Dataset which would make it even easier. Take a look at the Tutorial: Using a Dataset on a Regular Page to Display Content.
Good luck,
Yisrael
Thanks for your reply.
I do not want to connect the data.
The reason for this is because this page is already a dynamic page, but the set up of the dynamic page would result in not all items being pulled through.
Therefore, are you able to provide a solution that does not involve connecting data and only involves using code.
Thanks
Hmm, a dynamic page connects data.
If you want to use code, run a query on the database collection, and then assign the returned values to the elements on the page.
I think I have managed to do a work around.
I returned the page to an ordinary page.
Then linked the table to the datacollection (non-dynamically)
Then made the page a dynamic page again.
This now allows me to see all data in the datacollection, not just those linked to the _id of the dynamic page
I can now use code to filter the table as I need to.
Thanks for your help, and quick replies!
glad I could help - at least I hope I helped 