Hello, I just want to tell you straight off the bat that I’m new to this, so please bear with me. I have a repeater that is populated with a dynamicDataset. There is an edit button for each container which will open a lightbox that allows users to edit the values. I managed to pass the necessary values but for some reason, it won’t perform the update() function because it says “The dynamicDataset collection does not exist. You cannot work with a collection using the Data API before it is created in the Editor.”
Page Code:
Lightbox Code:
EDIT
For some reason, I could not post this if I paste the code as a code snippet.
2ND EDIT
If you can suggest an alternative way of doing this, I would greatly appreciate it.
@chocookie22 WixData functions work directly on the collection. The content manager knows nothing about that dataset name, consequently that error message.
From the documentation on the purpose of datasets: “A dataset serves as an intermediary between page elements, such as input elements and buttons, and the data in a collection. The dataset controls which collection is available to be used by page elements, what those elements can do with the collection data (display, add, modify), which item is currently active and whether the data is filtered or sorted.”
Be aware that mixing wixData functions on the same collection that the page’s dataset is tied to can be tricky. After issuing the update of the collection directly, the dataset won’t be updated unless you issue some dataset commands such as save and refresh . It will take you some time to understand the interplay of the actual collection data and the page’s dataset.
Personally, I avoid combining the two approaches. I use datasets only for a simple, straightforward display and update of data.
Oh wow, it took me a couple of days to get here and it definitely looks like I’m going to make a detour. Thank you so much for your input! Can you help me out in coding the update function that uses the dataset only?
EDIT
BTW, I was following this thread because simply I thought we had the same goal.
https://www.wix.com/corvid/forum/community-discussion/changing-the-value-of-database-from-repeater
@chocookie22 You would be well served spending some time with the dataset functions, so that you know what tools you have. In particular, setFieldValues is one of the functions available to use, but it would have to be used on the same page of the repeater.
Again, I would categorize your task as not simple and straightforward, so I would be populating the repeater via wixData.query and remove the dataset entirely. But, you have probably developed a comfort level with datasets.
@tony-brunsman Alright, I made some changes and it appears to be working.
Instead of opening a lightbox, selecting a record now takes me to another dynamic page which has the values of the selected record.
I made a very rough code just to test it out.
export function editButton_click ( event , $w ) {
let name = $w ( ‘#input1’ ). value
$w ( ‘#dynamicDataset’ ). setFieldValue ( “title” , name )
$w ( “#dynamicDataset” ). save ()
This one works and it does update the value in the repeater on the previous dynamic page. Am I on the right path?
Hi @chocookie22 
When you pass the data to the lightbox, you need to pass back the response to let your page code know whether the update process seceded or not, and refresh the dataset accordingly.
// Lightbox
$w('#saveBtn').onClick(() => {
const data = lightbox.getContext();
return wixData.update('col', { _id: data.id, title: $w('#nameField').value })
.then(() => {
lightbox.close({ type: 'success' });
})
})
// page
const dataset = $w('#dataset');
const item = $w('#dataset').getCurrentItem();
$w('#editName').onClick(() => {
wixWindow.openLightbox('editLightbox', { id: item._id, title: item.name })
.then((result) => {
if (result.type === 'success') {
dataset.refresh();
}
})
})
Hello @ahmadnasriya ! Terribly sorry but this question might sound stupid, is this the entire code I need for the update, or do I insert it somewhere in the code I posted? I tried replacing all the update-related code with this and I get the same error message saying " The col collection does not exist. You cannot work with a collection using the Data API before it is created in the Editor."
@chocookie22 the collection name is made up, you need to use your own, and no it’s not the whole code, you should just adapt it.