I been using this query for deleting all records in the collection. Its working fine. But not all in one extent. After sometime its getting stopped and when we press the button its going one by one
import wixData from ‘wix-data’;
$w.onReady( function () {
setTimeout(() => {
$w(“#table1”).refresh();
}, 3000);
});
export function outstanding_click(event, $w) {
//Add your code for this event here:
$w(“#delete”).onReady( async () => { if ($w(“#delete”).getCurrentItem()) { await $w(“#delete”).remove(); while ($w(“#delete”).hasNext()) { await $w(“#delete”).next(); await $w(“#delete”).remove()
}
}
});
}
You can use one of these two functions to delete all records.
Using a database query:
export function deleteAll_onClick(event, $w) {
wixData.query("NewCollectionName”)
.limit(1000)
.find()
.then((result) => {
for (var i = 0; i < result.items.length; i++){
if (result.items[i] === null) continue;
wixData.remove("NewCollectionName", result.items[i]._id);
}
console.log('erase done');
});
}
Using a dataset:
export function deleteAll_onClick(event, $w) {
let dataset = $w("#dynamicDataset"); // or the name of your dataset
dataset.onReady(async() => {
while (dataset.getCurrentItem()) {
await dataset.remove();
}
});
dataset.refresh();
}
I need another favor, which I have already raised but no reply yet. Need you help on the same.
I am trying to do a manual upload in Json form when I upload its perfectly working when it come to Date field am getting stuck.
What I did was made a hooks beforeInsert from UTC date format to Javascript Date Object. This is the code
export function LM_Attendance_beforeInsert(item, context) { let hookContext = context; // see below
var str = item.at_date; var dt = new Date(str + “Z”); let at_date_date = dt.getDate(); let at_date_month = dt.getMonth()+1; let at_date_year = dt.getFullyear(); let at_date_hours = dt.getHours(); let at_date_minutes = dt.getMinutes(); let at_date_sec = dt.getSeconds(); let at_date_full = new Date(at_date_year, at_date_month, at_date_date, at_date_hours, at_date_minutes, at_date_sec, 0)
item.at_date = at_date_full return item;
}
Its not working.
Date is coming but the time is showing as 5 30 am in the database. Am I doing the right thing.
Hi Yisrael,
Can you please help me.
I have 10 collections, each collection has near 8000 items. Every couple of weeks I need to delete all the items (Rows )in each collection ( including Live) and import new items.
I spend a very long time highlighting rows and clicking the delete button. I am absolutely exhausted when it all deleted.
I notice above you have given two codes
1)Using a database query
2) Using a dataset
I tried No 2) But the items in the collections are not deleting.
This is what I did:-
1)Opened a New page
2) Added a Dataset
3) connected the Dataset to Dresses
4) Added the code that you have given in “No. 2 Using a datase”
But when I go to the Dresses Collection all the items are there.
Please tell me what I am doing wrong here.
How can I delete all the rows on the Dresses Live well
Really appreciate your advice.
I have a very little knowledge about coding, so can you please write things down step by step.
Thanks.
I added a test page to your site, put a button on the page, added a dataset connected to the mypage collection, and then used this code:
export function deleteAll_click(event, $w) {
let dataset = $w("#dataset1"); // or the name of your dataset
dataset.onReady(async() => {
while (dataset.getCurrentItem()) {
console.log('x');
await dataset.remove();
}
});
dataset.refresh();
}
It works fine.
You can also use this:
export function deleteAll_onClick(event, $w) {
wixData.query("mypage”)
.limit(1000)
.find()
.then((result) => {
for (var i = 0; i < result.items.length; i++) {
if (result.items[i] === null) continue;
wixData.remove("mypage", result.items[i]._id);
}
console.log('erase done');
});
}