Enquiries on displaying information within a lightbox obtained from a content database.

I’ve got some knowledge with coding conventional languages, but not much experience with Corvid.

The long version is:
I’m currently trying to set up a system within a page that has multiple cards created by a database-connected repeater that displays concise & unique content for each repeated card.
Upon clicking any card, a lightbox that’s also connected to the same database will pop up and show additional information corresponding to the card that was clicked.

The short version is:
I want to make it so that if a user clicks card #23, it’s able to show more expanded information from database entry #23 through a lightbox card popup.

The only linkage I’ve done is as mentioned above, where the database was linked to a repeater card so as to show all the unique cards, as well as connecting the lightbox popup’s elements to the database in a similar fashion.

While I’ve looked around with posts regarding querying a database to get information (one of them being here ), I’m still unsure about what to do to create a query to extract specific information from a linked database like intended.

Any guidance and assistance will be much appreciated!:smile:

How to get data out of your DATABASE, how to filter it and how to use the results of the filtered data… ?..

Let us say you have a DATABAS-A in this DATABASE you have 5-COLUMNS full of DATA.

  1. You start querying the data of your DB… DB-NAME = “DATABASE-A”
import wixData from 'wix-data';

wixData.query("DATABASE-A")
  .find()
  .then( (results) => {
    if(results.items.length > 0) {
      let firstItem = results.items[0]; 
    } else {
     
    }
  } )
  .catch( (err) => {
    let errorMsg = err;
  } );
  1. When you input the following filter-command–> .contains(“column”, “value”)
    you will get filtered DATA-RESULTS.
import wixData from 'wix-data';

wixData.query("DATABASE-A")
  .contains("column-1", "value")
  .find()
  .then( (results) => {
    if(results.items.length > 0) {
      let firstItem = results.items[0]; 
    } else {
     
    }
  } )
  .catch( (err) => {
    let errorMsg = err;
  } );

Now you are able to filter the data by a valued seach-term (“value”) in a specific column of your DB.

You will get an OBJECT of RESULTS, where you can find all of the founded/filtered DATA…

.then( (results) => {     }

Now you can check your results…

import wixData from 'wix-data';


wixData.query("DATABASE-A")
  .contains("column-1", "value")
  .find()
  .then( (results) => {
    if(results.items.length > 0) {
    let myRESULTS = results
    let myResultItems = results.items
    let myFirstFoundItem = results.items[0].title
    console.log(myRESULTS)
    console.log(myResultItems)
    console.log(myFirstFoundItem)
    
      let firstItem = results.items[0]; 
    } else {
     
    }
  } )
  .catch( (err) => {
    let errorMsg = err;
  } );

“title” will be the ID of your first column!

To complete this code you can put it into an own function…

function myFirstFunction() {
  wixData.query("DATABASE-A")
  .contains("column-1", "value")
  .find()
  .then( (results) => {
    if(results.items.length > 0) {
    let myRESULTS = results
    let myResultItems = results.items
    let myFirstFoundItem = results.items[0].title
    console.log(myRESULTS)
    console.log(myResultItems)
    console.log(myFirstFoundItem)
    
      let firstItem = results.items[0]; 
    } else {
     
    }
  } )
  .catch( (err) => {
    let errorMsg = err;
  } );
  }

Your CODE is almost complete… (What you still need is to call this function, for example when page loads…like this…)

This is the onReady-Function of your page…(when page is loaded completely this function triggers an action.

$w.onReady(function () {        })

Your End-code would look like this…

$w.onReady(function () { myFirstFunction() }) //start of func.
  
function myFirstFunction() {
  wixData.query("DATABASE-A")
  .contains("column-1", "value") //or using .eq("ref","value")
  .find()
  .then( (results) => {
    if(results.items.length > 0) {
    let myRESULTS = results
    let myResultItems = results.items
    let myFirstFoundItem = results.items[0]
    let myFirstFoundItemsTitle = results.items[0].title
    console.log(myRESULTS)
    console.log(myResultItems)
    console.log(myFirstFoundItem)
    console.log(myFirstFoundItemsTitle)
    
    } else {
     
    }
  } )
  .catch( (err) => {
    let errorMsg = err;
  } );
  }

Test this code with your own DATABASE and take a carefully look into your CONSOLE. You will find it in the preview-Mode on the very bottom of the page.
Or if you are using the published version of your site you can press F-12 in your google-chrome browser and go to CONSOLE.
There you will also be able to find all results, which you have just created a few minutes ago.

The last step of your coding-adventure will be to connect your RESULT-DATA with your LIGHTBOX, to show results in it.

For this you will need to use the Wix-Storage (session or local command).
How to manage that, you will find here in this example …

https://russian-dima.wixsite.com/meinewebsite/lightbox

More informations about Wix-DATA and Wix-STORAGE you will find in the CORVID-API-REFERENCE.

Good luck and happy coding!:grin:

Well, first off, I have to thank you for the extremely detailed explanation (though I don’t fully understand everything), I appreciate your time and effort!:smile:

Through the steps you mentioned, I’m still unaware as to where the link between the clicking of the card, and pinging back to the connected database occurs. I’m also unsure as to how to get the query and the code to distinguish which specific repeater container was clicked, out of the hundreds that are within our existing repeater.

I think if I can understand this first part, and successfully set up some successful connection, it would help in successfully implementing this system.

@joellim
Let me know, if you could solve your issue :wink:

@russian-dima I’ve done a bit of searching around, and I’m still unable to find posts about defining the classes of each repeater-created card. Even in web console mode (F12) I don’t easily see an id or class tag anywhere for each card.

Would you by any chance know how I can obtain the id or class tag for each repeater-created card? I’m moving in the direction where I’m planning on utilising that to create my query, and I’ll need to know how to obtain that!