Implementing Delete

To make it possible to delete records from the database, I added a button to every row in the Presenters table.

TableWithDelete

The button has a sys:command attribute of Delete, and the sys:commandargument parameter is $dataItem, as it was for the Select command we looked at before.  The Presenters table now has an extra function, but is inferior in appearance:

MasterViewWithDelete

When a delete button is clicked, the onCommand function is called, as it is when a presenter’s name is selected.

FinalonCommand

The commandname is stored as a property of the args object, and is accessed through the get_commandName method.  If it equals Delete, the commandargument, which we have set to be the data to be deleted,  is retrieved with the get_commandArgument method.  A confirm box is displayed; and if the response equates to true, the data is deleted with the removeEntity method, and the changes are saved to the database with the saveChanges method.  Although the data has now been deleted, it is still visible in the DataView.  If the DataView was bound to the DataContext, the deleted item would be removed from the DataView, but it would only display nine items, which could cause problems with paging.  Instead, the SaveSucceeded function checks whether the context equals Delete; and if it does, it causes the DataView to refresh.

SaveSucceeded

Advertisements

2 Responses to “Implementing Delete”


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: