How do I delete an entry

Ok Ive got a form that the user can fill in and I can display the contents of that collection
but I need to be able to remove a single entry at a time as some users are filling out my form incorrectly- how do I create a delete Admin feature-very simple as I new

sorry that doesnt read right
I want to build a facility that will enable me to remove a record from the database

Hi,
You can simply right click on the record line and delete it. Do you wish to create a page for this scenario instead of deleting is from the editor?

Tal.

Yes Tal i want a page for this purpose as i dont want my users gaining access to the editor-cheers

Hi,

You can create a password protected admin page and share the password only with the people who should have access to it.

Use dataset actions to control the collection
See more here


This is my table and users are not always filling them in correctly I wish to be able to delete one row of my choice -Is this possible if so how do I achieve this- Ive tried adding a button and conntecting it to the dataset but the button function delete is not available - can anyone send me a picture of how it would look
Thanks jer

Hi,
Lets say that you’ve connected a table to your DB collection. Make sure to set the dataset mode is " Read & Write ". Than, you should add a table row event and once someone clicks on the table row, it will be deleted from the collection by adding the following code:

import wixData from 'wix-data';

export function table1_rowSelect(event, $w) {
	//get the index of the row which was clicked by the user	
	const index = event.rowIndex; 
	//get the _id attribute of the relevant record
	const idToDelete = event.target.rows[index]._id;
		
	//remove the record from the collection			
	wixData.remove("collectionName", idToDelete)
		.then(() => {
		//refresh the table with the updated info
			$w('#table1').refresh();
		})
		.catch((err) => {
			let errorMsg = err;
		});
}

I recommend, as Ido suggested, to set a password to the page so that only the relevant people will have permission to delete records from your collection.

I hope it’s clear.

Best,
Tal.

how do I add a table row event ive looked through Wix support but cant find it
Ive password protected the page so all good there-i just now need to have the option to delete a row
Thankyou for your help Tal

Hi,

Add an onRowSelect() function:


This will create the following code in the code pane:

export function table1_rowSelect(event, $w) {
	//Add your code for this event here: 
}

See the API doc for https://www.wix.com/code/reference/$w.Table.html#onRowSelect for more information.

Yisrael


OK got that bit but when I paste the code that Tal gave me I get a ton of errors - do I have to add a button I dont get where the action of the code should go-Im from an XCode background and this confusing to me
thanks for helping everyone
Jer

The code that Tal provided needs to go in the table1_rowSelect() function. You need to change collectionName to the name of your database collection.


HHmmm

The import wixData from ‘wix-data’; statement should go at the top of the file.

Delete the first export function table1_rowSelect(event, $w)

I would suggest familiarizing yourself with basic coding concepts to enable you to accomplish what you want. There are a wealth of Javascript coding sites which will help you learn Javascript from basic to advanced - Javascript.info is a good one.

Here’s the corrected code:

import wixData from 'wix-data';

$w.onReady (function () {

});

export function table1_rowSelect(event, $w) {
   //get the index of the row which was clicked by the user    
   const index = event.rowIndex; 
   //get the _id attribute of the relevant record
   const idToDelete = event.target.rows[index]._id;
 
   //remove the record from the collection         
   wixData.remove("FutureData", idToDelete)
      .then(() => {
          //refresh the table with the updated info
          $w('#table1').refresh();
      })
      .catch((err) => {
           let errorMsg = err;
      });
}

Yea sorry that didnt work either so I will try to get my head around it later
Regards Jer

OOHHH cant seem to find out how this works please can someone help ive tested on Mac and PC

Hi,

Add console.log(‘user selected a row’) below the function declaration line to make sure the event is executed. If you do not see this message when you click a table row re-add the onRowSelect event and try again.

No the event is not executing Ido is it possible to do this- is the code in previous messages the correct code or should I start again- I was hoping to put a checkbox in the table so that if the Administratot selects it the row will disappear or a button to execute the delete of the row in the table- has anyone got this working

Hi,

Yes, the code should work. Make sure to add the onRowSelect event from the table properties panel.

As an alternative, you can show a lightbox as a confirmation window (to prevent accidental deletions)
See the thread here to get a basic idea on how to achieve that.

Im getting in a right mess here ive read so much and still cant get this working can anyone look at my table to see whats going on for meRegards Jer