Remove / Delete Item from Dataset with Code

Hi I’m trying to delete an item from my dataset using code, then re-set the dataset to show the most recent changes in the repeater. The button is placed on the repeater.

I have this so far but it’s not working:

export function iconButton1_click(event, $w) {
	
	        let item = $w("#dataset1").getCurrentItem();
		let title = $w("#text153").text; // key generated as page loads so the filter has something to match tp
		wixData.remove("images", item)
	
		$w("#dataset1").onReady( () => {

			$w("#dataset1").setFilter(wixData.filter().eq("title", title)); // should filter dataset to match text153
						
		})
	
}

Any idea what’s going wrong?

Many thanks

Thomas

Hi,
Yes, remove method is expecting collection’s name and an id.
So, it should look like this:

wixData.remove("images", item._id)

Good luck!
Roi.

Hi Roi

Worked a treat. However, the repeater isn’t refreshing as expected.

I’ve tried:

$w('#repeater4').refresh();

but it says it does not exist on the repeater.

This is my repeater layout:

Many thanks!

Thomas

After it removes the item (Promise) refresh the dataset.
Roi.

Hi Roi

I’ve added this to my code but nothing seems to be working with the refresh of the dataset on the screen

export function iconButton1_click(event, $w) {
	
	        let item = $w("#dataset1").getCurrentItem();
		let title = $w("#text153").text; // key generated as page loads so the filter has something to match tp
		wixData.remove("images", item)

 
                   .then( () => {
                        $w("#dataset1").refresh()
                        console.log("Done refreshing the dataset");
                   } );


	
		   $w("#dataset1").onReady( () => {

			$w("#dataset1").setFilter(wixData.filter().eq("title", title)); // should filter dataset to match text153
						
		   })
	
}

I’m not sure if I’ve followed your instructions correctly? I’m assuming not!

Thanks again for the help

Thomas

Hi,
Can you please share a link to your site and specify the name of the page so we can inspect?
Roi.

Hi Roi

Thanks for the reply but I’ve managed to get it working.

My code ended up as a pretty simple fix:

export function vectorImage97_click(event, $w) {

	delay(function () {

		$w("#dataset1").remove()
      		.then( () => {
        		console.log("Done removing current item");
      		} );

	}, 500); 
}

Thanks again!

Thomas