I want the user to be able to select the student name from a drop-down menu. Then create several tables about that student (from different collections). E.g. User selects “John”, then an attendance table, grade table, and student information table appear.
I have successfully created one table from the dropdown using javascript, but I don’t know how to create more because I can only link 1 dataset to the drop-down user input.
Hello 1) it should be written this way: let tableData = results.items 2) you fill this section based on your table fields and you data fields. so lets say you have two columns, one with field studentName and one with field key number. and in the database you have a field studentName and a field number, the data would look as follows:
note that this step is not always needed, you can simply skip it if the table keys are the same as the data set’s.
$w("#myTable").rows = results.items;
you can query each collection with its own query, and get a results array of each, lets say:
let results1 = await wixData.query("myCollection1") .eq("student-name-field",student).find()
let results2 = await wixData.query("myCollection2") .eq("student-name-field",student).find()
and then you create the data for each table based on which results has it.
I checked your editor, I assumed the page you’re asking about is “New Page”:
you can’t have two onReady functions, set both tables columns in the first (and should be only) onReady.
on drop down value change function works correctly, it should be looking like this:
export async function dropdown1_change(event) {
let res = await wixData.query("StudentInformation")
.contains("student_id", $w("#dropdown1").value)
.find() // Run the query
// Set the table data to be the results of the query
$w("#table1").rows = res.items;
$w("#table1").expand();
}
in order to show the second table you need a button click event and inside of it you query the collection (attendance) based of the referenced field is :
export async function button1_click(event) {
//to get the referenced field id
let studentId= $w('#table1').rows[0]._id
let res = await wixData.query("Attendance")
.hasSome("student_id", studentId)
.find() // Run the query
// Set the table data to be the results of the query
$w("#Attendance").rows = res.items;
$w("#Attendance").expand();
}