Deleting rows from a database
In the previous sections, we managed to build a system where we could add new messages, list them, and paginate them. But so far, we are unable to delete anything.
The way the project is structured, it is really quick to implement:
- We check in
/app/website/templates/components/_list-messages.html
that we are adding to each button a dataset with theid
. We do this task when we list the messages; we must be aware of the source where theid
that we will use comes from to know which message we must delete:<button class="button messages__delete" data-id="{{ message.id }}"> Delete</button>
- In
/static/js/index.js
, add thedeleteMessage
function. We will capture the dataset with the id and send it to the consumer with the action"delete message"
. In addition, we will add each listener after the listener of the pager. Let’s not forget the reason for this positioning: all events...