Hey Wix team,
I have a table (table1) connected to a dataset (dataset1) inside a Lightbox that I’m launching from a repeater. I’m trying to set the table to show only filtered rows based on a parameter passed to the Lightbox. The parameter is string but in the database it is a referenced value. I tried either filtering the dataset based on this parameter (didn’t work) also tried adding a filter to the dataset based on a simple text, which also didn’t work. I also tried to remove the connection between the table and the dataset and simply just run a query on the collection, which also didn’t work. All string data points transferred to the Lightbox are working wonderfully and I’m able to set those to labels / texts.
Here is what I’ve done:
import wixData from ‘wix-data’;
import wixWindow from ‘wix-window’;
$w.onReady(() => {
let receivedData = wixWindow.lightbox.getContext(); // to receive the information
//ALL THESE WORKING WELL:
$w(“#text349”).text = receivedData.data.test;
$w(“#text306”).text = receivedData.data.courseType;
$w(“#text313”).text = receivedData.data.dates;
$w(“#text348”).text = receivedData.data.courseLength;
$w(“#text309”).text = receivedData.data.days;
$w(“#text312”).text = receivedData.data.startTime;
$w(“#button4”).link = receivedData.data[“link-Courses-title”];
$w(“#button2”).link = receivedData.data.productUrl;
$w(“#button3”).link = receivedData.data.productUrl;
$w(“#text368”).text = receivedData.data.originalPrice;
$w(“#text428”).text = receivedData.data.originalPrice;
var filter = wixData.filter().contains('SessionCode', currentCourse.value);
$w("#dataset1").setFilter(filter);
$w("#table1").rows = $w("#dataset1").getItems();
$w("#table1").refresh(); //Tried with or without refresh
You can either connect the dataset to the referenced collection and query it like you try to do today or use include in order to get the referenced fields and then perform the query on the results.
How can you connect the dataset in the light box to the referenced collection? Is there a way to transfer the referenced collection from the main page to the lightbox?
Say you have collectionA which holds your courses data. It has a reference field called SessionCode that references another collection - collectionB.
On your lightbox, add a dataset and connect it to collectionB. When you get the data in the lightbox using getContext, create a filter on this dataset to get all the items that have the SessionCode you received.
Shalom Ohad/Elad/All
Need help to pass data from repeater populated by query with include to Lightbox (the include part going to Lightbox).
What is a statement instead of
wixWindow.openLightbox(lightboxName, dataObj);?
You use the openLight box and your dataObj would then be the data you want to pass to the lightbox.
So
let lightBoxData = { 'repeaterData': <the data to send> };
wixWindow.openLightbox("The Lightbox", lightBoxData);
Then when your lightbox opens, in your lightbox $w.onReady() function you need to have it get the data passed using the getContext() function.
Add this code to your lightbox page code
$w.onReady(() => {
let receivedData = wixWindow.lightbox.getContext();
let repeaterData = receivedData['repeaterData'];
});
Hope this helps
Thank for reply
Here is a sample of code that doesn’t work
The target is to open different Lightboxes (with data passing) for any related item in repeater on dynamic page.
import wixData from 'wix-data';
import wixLocation from 'wix-location';
import wixWindow from 'wix-window';
let iQuery = wixData.query('Items');
let pQuery = wixData.query('Persons');
let lightboxName;
let dataObj;
$w.onReady(function () {
$w("#aDataset").onReady(() => { populateCalculatedFields(); });
$w("#aDataset").onCurrentIndexChanged((index) => { populateCalculatedFields(); });
});
function populateCalculatedFields() {
const currentItem = $w("#aDataset").getCurrentItem();
$w("#aTitleText").text = currentItem.pFullName;
setAuthorItemsRepeater();
}
function setAuthorItemsRepeater() {
const currentItem = $w("#aDataset").getCurrentItem();
let asObject = currentItem._id
iQuery
.eq('iAuthor', asObject)
.include('iKeeper')
.find()
.then((results) => {
console.log(results.items);
$w(`#aiRepeater`).data = results.items;
}) //console.log(results);
.catch((error) => {
let errorMsg = error.message;
let code = error.code;
});
$w('#aiRepeater').onItemReady(($w, iData, index) => {
$w("#aiNameText").text = iData.iName;
if (iData.iKeeper !== null && iData.iKeeper !== undefined) {
$w('#adoptButton').label = 'Look';
lightboxName='Hall';
dataObj=iData.iKeeper; //include } else {
$w('#adoptButton').label = 'Take';
lightboxName='Artwork';
dataObj=iData.iKeeper;}
$w(`#adoptButton`).onClick((event)=>{ wixWindow.openLightbox(lightboxName, dataObj) });
});
}
import wixWindow from 'wix-window';
$w.onReady(function () {
let receivedData = wixWindow.lightbox.getContext();
$w('#kImage').src = receivedData.pImage;
$w('#kTitleText').text=receivedData.pFullName; .
});
Currently even open Lightbox with lightboxName as parameter doesn’t work
May be it is scope/context issue?
!!!https://www.wix.com/code/home/forum/wix-tips-and-updates/removal-of-the-w-parameter-from-event-handlers
https://www.wix.com/code/home/forum/wix-tips-and-updates/removal-of-the-w-parameter-from-event-handlers
https://www.wix.com/code/home/forum/wix-tips-and-updates/connecting-your-database-to-lightboxes
Please urgent help
Do you have a link to the page that you are having problems with?
Several observations with the code posted (which is why looking at the page code will be more helpful).
- your $w(‘#aiRepeater’).onItemReady handler shouldn’t be declared inside of another function. It is best to declare it in the $w.onReady() function. It will run anytime the data array changes OR the dataset is loaded or filtered.
- You seem to be using wix-data AND wix-dataset together. Make sure you know what you are doing as it is possible that using both mechanisms to access your data collection can lead to unexpected results. Especially if you have elements on your page connected to the data set using data binding. Is $w(‘#aiRepeater’) connected to a dataset? Is it $w(" #aDataset ") or do you ONLY populate data in the repeater using the .data property?
- The $w(
[#adoptButton](https://www.wix.com/code/home/forum/search/posts%3Fquery=%23adoptButton)
).onClick() should be declared in the $w.onReady() function. The event argument delivers a new context value that you use to determine which repeater element is being used for the button press. This is what the $w.at() function is there for.
If you are familiar with the DOM, think of the repeater element as one of several attached to a common repeater node e.g.,
document.repeater.item1.adoptButton
document.repeater.item2.adoptButton
etc.
When you click on a button the Wix system figures out that you need element information scoped to a specific item. So getting the $w.at() value essentially provides you the repeater item scope you need to get the correct button value
for example
$w(`#adoptButton`).onClick((event)=>{
let $repeaterItem = $w.at(event.context);
let lightboxName = $repeaterItem('#adoptButton').label;
let keeperInfo = $repeaterItem('#keeperElement').text;
wixWindow.openLightbox(lightboxName, keeperInfo);
});
If the adoptButton is clicked on the repeater view for item2 then this code will use the event context to point $repeaterItem to all of the elements connected to document.repeater.item2 node. If the lightbox name was used as the label for the adoptButton then the lightbox name would be set from the button label. If you have a text box (this could be visible or hidden) that contained the keeper information (assuming this is a text value) then this would create the lightbox data from that element value. Then the light box would be launched using these arguments.
I hope this makes sense.
Bottom line you probably need to re familiarize yourself with event handlers and how datasets work with repeaters and you will probably end up with less code to do what you want
Site is not published yet. How I can copy a link for You?
https://www.seniorsartmuseum/Storage/{Person ID}
The page is dynamic with dataset for authors. Related artworks (repeater) for each author are populated from query. Repeater is not connected to dataset.
I’m grateful for your help
The best way to help would be as an authorized contributor. If you are comfortable giving me that access I can look at the site directly in the editor for you. Check my profile for how to contact me.
THIS! This solved my problem! I suspected it might be tied to the $w.at command but I wasn’t too sure about how to properly implement it.
Thanks!