Delete selected record in datagrid2 Mendix

0
The current problem, I can't get the list of checked records to proceed with the deletion. List of data.     Domain Microflow get data from Database
asked
2 answers
1

Hi Doan Duong,

 

If your “Delete” button is a Delete button it will not work. This is because of two reasons:
1). the non-persistent objects do not exist anymore as your pasted microflow is finished. 
2). The association is not cleaning up the DataDB object when the DataGrid object is deleted. You can set that behavior in the properties of the association.

In the end what you want is what you can achieve with adding another Attribute called MarkForDeletion as Boolean and set the “Store ‘changeBy’”

 

 

 

Create the grid2 and in the checkbox on the MarkedForDeletion Boolean, with the Events “On change” → “Save changes” set.

 

 

The ACT_DataDB_MarkForDeletion_Delete

The [System.changeBy = $currentUser] makes you only delete the MarkForDeletion the user just set.

 

This is the easy version with one flaw. Your DataDB has 3 records: 1, 2 and 3. User 1 is marking 1 and 3 for deletion. User 2 is marking 1 for deletion just after User 1 but before User 1 hits the Delete button. In that case, only 3 gets deleted. If user 2 doesn’t hit the Delete button, user 1 will see record 1 again. (But if he check it and deletes it before User 2 does check it again it will work). If you want to prevent this rare scenario you should implement some logic on the On change event of the MarkForDeletion checkbox in your Grid2. You can check if it is already set by someone else and give an appropriate response. 

 

GoMake It,

 

If this works for you please accept the answer

 

answered
0

I think your problem might be the database retrieve. You are using a non persistable entity to check if your objects are selected or not. But you can’t use the non persistable entity in your xpath retrieve. Your retrieve will just not know which one is selected or not.

Maybe it helps to have a persistable helper object per user and have a many to many association between your objects and the helper. Clicking the checkbox can then add or remove the object from the association.

When clicking delete you can just retrieve the list of selected objects via the association on your helper object.

 

The benefit is that you can also store personal datagrid 2 settings from your user in that helper.

answered