Alas, I need assistance. To keep this short and sweet, I am working on a trading card game database. What I want to do is by using the onRowSelect() function, I want to update an image’s src to the src of an image from the selected row.
So, in this snapshot, if I was to click on the row where it shows the card “Dustrog Crystals”, the image of the card “Rokah” (enlarged above) would update to Dustrog Crystals.
Make sense?
Everything else in my code works fine, but I’m not too sure how to implement this. Any assistance would be greatly appreciated!
Here’s my code as of writing this post. It’s not entirely complete, as the code is a WIP, but essentially all I need assistance with is the onRowSelect() function.
import wixData from 'wix-data';
const databaseName = 'CardDatabase';
const databaseField = 'planet';
const databaseField2 = 'cardType';
const databaseField3 = 'stars';
const databaseField4 = 'rarity';
const databaseField5 = 'power';
const databaseField6 = 'health';
const databaseField7 = 'newField'
const fieldTitle = 'title';
let debounceTimer;
$w.onReady(function () {
$w('#input1').onInput((event) => {
})
//Planet Type Checkbox onChange event
$w('#checkboxGroup1').onChange((event) => {
const selectedBox = $w('#checkboxGroup1').value; //Planet Type
const selectedBox2 = $w('#checkboxGroup2').value; //Card Type
const selectedBox3 = $w('#checkboxGroup3').value; //Rarities
const dropDown = $w('#dropdown1').value;
const minPower = $w('#minPower').value;
const maxPower = $w('#maxPower').value;
addItemstoRepeater(selectedBox, selectedBox2, dropDown, selectedBox3, minPower, maxPower);
})
//Card Type Checkbox onChange event
$w('#checkboxGroup2').onChange((event) => {
const selectedBox = $w('#checkboxGroup1').value; //Planet Type
const selectedBox2 = $w('#checkboxGroup2').value; //Card Type
const selectedBox3 = $w('#checkboxGroup3').value; //Rarities
const dropDown = $w('#dropdown1').value;
const minPower = $w('#minPower').value;
const maxPower = $w('#maxPower').value;
addItemstoRepeater(selectedBox, selectedBox2, dropDown, selectedBox3, minPower, maxPower);
})
$w('#checkboxGroup3').onChange((event) => {
const selectedBox = $w('#checkboxGroup1').value; //Planet Type
const selectedBox2 = $w('#checkboxGroup2').value; //Card Type
const selectedBox3 = $w('#checkboxGroup3').value; //Rarities
const dropDown = $w('#dropdown1').value;
const minPower = $w('#minPower').value;
const maxPower = $w('#maxPower').value;
addItemstoRepeater(selectedBox, selectedBox2, dropDown, selectedBox3, minPower, maxPower);
})
$w('#dropdown1').onChange((event) => {
const selectedBox = $w('#checkboxGroup1').value; //Planet Type
const selectedBox2 = $w('#checkboxGroup2').value; //Card Type
const selectedBox3 = $w('#checkboxGroup3').value; //Rarities
const dropDown = $w('#dropdown1').value;
const minPower = $w('#minPower').value;
const maxPower = $w('#maxPower').value;
addItemstoRepeater(selectedBox, selectedBox2, dropDown, selectedBox3, minPower, maxPower);
})
$w('#maxPower').onInput((event) => {
const selectedBox = $w('#checkboxGroup1').value; //Planet Type
const selectedBox2 = $w('#checkboxGroup2').value; //Card Type
const selectedBox3 = $w('#checkboxGroup3').value; //Rarities
const dropDown = $w('#dropdown1').value;
const minPower = $w('#minPower').value;
const maxPower = $w('#maxPower').value;
addItemstoRepeater(selectedBox, selectedBox2, dropDown, selectedBox3, minPower, maxPower);
})
$w('#minPower').onInput((event) => {
const selectedBox = $w('#checkboxGroup1').value; //Planet Type
const selectedBox2 = $w('#checkboxGroup2').value; //Card Type
const selectedBox3 = $w('#checkboxGroup3').value; //Rarities
const dropDown = $w('#dropdown1').value;
const minPower = $w('#minPower').value;
const maxPower = $w('#maxPower').value;
addItemstoRepeater(selectedBox, selectedBox2, dropDown, selectedBox3, minPower, maxPower);
})
//THIS IS WHAT I NEED ASSISTANCE WITH
$w('#table1').onRowSelect( (event) => {
let rowData = event.rowData;
console.log(rowData); // {"fName": "John", "lName": "Doe"}
let rowIndex = event.rowIndex; // 2
console.log(rowIndex);
//What do? I'm stumped.
} );
});
function addItemstoRepeater(selectedOption = [], selectedOption2 = [], dropDown, selectedOption3 = [], minPower, maxPower) {
let dataQuery = wixData.query(databaseName);
if (selectedOption.length > 0) {
dataQuery = dataQuery.hasSome(databaseField, selectedOption);
}
if (selectedOption2.length > 0) {
dataQuery = dataQuery.hasSome(databaseField2, selectedOption2);
}
if (selectedOption3.length > 0) {
dataQuery = dataQuery.hasSome(databaseField4, selectedOption3);
}
if (dropDown > 0) {
dataQuery = dataQuery.hasSome(databaseField3, dropDown);
}
if(minPower > 0) {
if (maxPower > minPower) {
dataQuery = dataQuery.between(databaseField5, minPower, maxPower);
}
}
dataQuery
.find()
.then(results => {
const filtereditemsReady = results.items;
$w('#table1').rows = filtereditemsReady;
})
}
Any further questions just ask.
Thanks