I want to delete the items on my database collection from sandbox to live data collection
Hi geovel,
I’m not sure what you want to do. Do you want to delete from the sandbox or from the live? Or do you want to sync (copy) from the sandbox to the live?
Yisrael
Hi Yisrael .
Good day! I want to delete all the items in my database collection of sandbox and live.
Hi geovel,
You can delete two ways…
-
In the editor, you can select more than one row at a time of a collection, and then right click/delete.
-
Or, set up a temporary page, add a dataset and connect it to your collection. Add the following code to the onReady() function of the page:
$w("#dataset1").onReady(async() => {
if ($w("#dataset1").getCurrentItem()) {
await $w("#dataset1").remove();
while ($w("#dataset1").hasNext()) {
await $w("#dataset1").next();
await $w("#dataset1").remove();
}
}
});
Run preview and you delete the contents of the sandbox collection. Run the live site and you delete the contents of the live collection.
Just be careful you don’t trash something important.
Have fun,
Yisrael
Hi Yisrael ,
i have tried this successfully. However, it always leaves two items un deleted on mine
Hi,
Do you want to delete automatically? If you don’t and you want to delete the rows one time, you can delete them by right clicking the row’s number and pressing delete.
hi,
here’s my problem.
i have two datasets. 1. Client name(dataset1) 2. client’s images(dataset2).
the client images are referenced to the client name.
i want to build a page where i can select the client with a dropdown and then delete all the images of that client.
export function button13_click(event, $w) {
//Add your code for this event here:
$w("#dataset2").onReady(async() => {
if ($w("#dataset2").getCurrentItem()) {
await $w("#dataset2").remove();
while ($w("#dataset2").hasNext()) {
await $w("#dataset2").next();
await $w("#dataset2").remove()
$w("#dataset1").remove()
.then(() => {
//refresh the table with the updated info
$w('#table1').refresh();
$w('#dataset3').refresh();
$w("#box2").hide();
})
.catch((err) => {
let errorMsg = err;
});
}
}
});
}
Hi,
no need to use the data set in such a case. once you have selected a client, get its id and select the images from the other collection that references it. (they will all reference the client _id in their reference column)
so use http://www.wix.com/code/reference/wix-data.html#query to query all the items that has the client _id in their reference column. and use the wix-data api to delete them
good luck,
Shlomi
hi Shlomi ,
I’m good up until the query. but i have trouble removing the items from the database.
export function button13_click(event, $w) {
//Add your code for this event here:
$w('#dataset1').onReady(() => {
let deleteId = $w("#dataset1").getCurrentItem()._id;
wixData.query('APARTMANR-CLIENT-IMAGE')
.eq('client', deleteId)
.find() // Run the query
.then(results => {
if (results.items.length > 0) {
console.log("query results present");
let firstItem = results.items;
wixData.remove("APARTMANR-CLIENT-IMAGE", firstItem)
.then((results2) => {
let item2 = results2; //see item below
$w("#dataset1").remove();
//refresh the table with the updated info
$w('#table1').refresh();
$w('#dataset3').refresh();
$w("#box2").hide();
})
.catch((err) => {
let errorMsg = err;
});
} else {
console.log("no query results");
}
})
.catch((err) => {
let errorMsg = err;
});
}
);
}
Hi,
i’d skip refreshing the table, data set and anything else until the process is deleted. just execute the deletion and refresh only at the end. please let me know how it works out for you
Shlomi
Hi Shlomi,
my initial problem was solved by changing Yisrael 's code. Mentioned in this thread:
export function button13_click(event, $w) {
//Add your code for this event here:
let dataset = $w("#dataset2"); // or the name of your dataset
dataset.onReady(async() => {
while (dataset.getCurrentItem()) {
await dataset.remove();
}
});
$w('#dataset1').onReady(async() => {
while (dataset.remove()) {
let deleteId = $w("#dataset1").getCurrentItem()._id;
await wixData.query('APARTMANR-CLIENT-IMAGE')
.eq('client', deleteId)
.find() // Run the query
.then(results => {
if (results.items.length === 0) {
console.log("query results not present");
$w("#dataset1").remove();
//refresh the table with the updated info
$w('#table1').refresh();
$w('#dataset3').refresh();
$w("#box2").hide();
};
})
.catch((err) => {
let errorMsg = err;
});
}
});
}
thanks for your help with it.
Hello,
for some reason i cannot delete the rows in sandbox. I try to right-click but nothing happens. Can someone help me please? I am on Mac and using chrome.
Hi Yisrael and others.
I have read through several threads in search of a solution to this. I’ve found it helpful to export the dataset for local editing. Then create a new dataset and import the local csv file. A couple of minutes. This may suit people that are familiar with spreadsheets.
However, I’d be happier as a wix customer if developement added UI functionality to dataset editing. I don’t want to work with code, that doesn’t suit my clients, and I’d say that the reason most of us use wix is for the Wix User Interface experience, which in most cases provides.
Hope this helps anyone reading.