Clearing dataset fields

Hi,
Im looking for code that when a button is clicked it will trigger an event that goes into my dataset and clears all the information in all fields…basically resetting it to an empty dataset with the empty fields still in place.

Its for a shopping list creator…I need the user to be able to clear all to start an new list

Thanks

Im playing around with this code using the bulk remove function when I click the button
“Type” , “Ingredient” , “quantity” being the field names in my dataset, but nothing happens. it doesn’t remove any data.

I am new to this so any help would be great Thanks!

export function button2_click(event) {
//Add your code for this event here:

wixData.bulkRemove( “Membersordersheet” , “Type” , “Ingredient” , “quantity” )
.then( (results) => {
let removed = results.removed; // 2
let removedIds = results.removedItemIds; // see below
let skipped = results.skipped; // 0
} )
. catch ( (err) => {
let errorMsg = err;
} );

import wixData from ‘wix-data’;

// …
$w.onReady(() => {
$w(“#button1”).onClick(() => {
wixData.truncate(“myCollection”)
.then( () => {
console.log(“All items removed”);
} )
.catch( err => err);
})
})

Thank you !!

You’re welcome :slight_smile:

So…I did this and it worked great, however working with it now i realize it’s not ideal. I’ve multiple users logged on making lists so cant really have the whole dataset being deleted all the time.
I have the dataset filtered to only show information submitted by the logged in user…but now I’m stuck on a way for users to click a button to clear only their inputted data…how would i go about this please?

I’m trying this but cant seem to get it to remove the data…any ideas whats wrong please?

var array = ;

export function dataset1_ready() {
let count = $w( “#dataset1” ).getTotalCount();
$w( “#dataset1” ).getItems( 0 , count)
.then((res) => {
let items = res.items;
items.forEach((item) => {
array.push(item._id);
});
});
}
export function button3_click(event) {
wixData.bulkRemove( “Membersordersheet” , array)
.then( (results) => {
console.log(results);
})
. catch ( (err) => {
console.log(err);
});

wixLocation.to( “/newpage1” )
}