Description

Learn how to use a table component to delete single or multiple entries from the database.

Video recorded using: Ignition 7.9

Transcript

(open in window)

[00:00] For an example of how to remove data from your database, I'm going to use a window that we created in a previous video. Our database manipulation window here contains a table that's bound to a sequel query. That sequel query's bringing back all the data from an inventory table I have in my database. Deleting data is a fairly simple task and requires us to change the table selection mode, add a button to our window as well as a short script. The table selection mode is going to determine whether or not we allow for multiple deletes or just a single delete. If you only allow for a single selection, then only one item can be deleted at a time. However, if you select Multiple Interval, it'll allow you to select multiple non-contiguous items in the table and delete them all at once. Now, let's create a button here for our delete. I'm going to go ahead and duplicate our edit button that we have here. And we'll make some changes to it. We'll call this "Delete." And we will change our image on here to show one that's more delete appropriate. And we also need to change the text. Okay. Now, with that done, we'll add a script to the action performed, and what we'll do here is delete what we had in here for what we would have got from duplicating out edit button. And we're going to add a new script. What this script does is sort the data from the table component in a data variable, and it stores a list of selected row indexes in a "rows" variable. You can get this list by calling "get selected rows," which is a special function of the table component. Next, we'll write a "for" loop that'll loop through all these rows, get the value from the data set that corresponds to the ID for that item. And then we're going to run a delete query using that ID to delete that row. If you only have one item selected, there will only be one row in the "get selected rows" that is returned, and so only one thing will be deleted. If you have multiple selected, multiple things will return. And multiple items will be deleted. Let's show an example of this. Put the designer into preview mode. I'll select one item here. Click my "Delete" button. And you'll see that my table is updated in the rows deleted. Now let's delete two things. I click here. I'll hold down Control. And we'll click this one right here. Hit "Delete" again. And after the table updates, you'll see that those two items are deleted as well.

You are editing this transcript.

Make any corrections to improve this transcript. We'll review any changes before posting them.