i have an angularJS app.controler with a datatable inside. in the last column is a delete-button. if i press this button should appear a modal dialog with a question "Do you realy want to delete this user?"
That is working fine.
But how can i display the username in the modal dialog?
and how can i send the userid to the backend-controller?
if i write this
return '<a class="btn btn-danger btn-sm btn-block" href=/deleteUser?userid=' + data + '>' + ($filter('translate')('delete')) + '</a>';
the user will be delete immediately.
this is my table:
usertable
the modal dialog: the modal dialog in action (without the username)
this is a snippet in html
<div id="myModal" class="modal">
<div class="modal-content">
<div class="modal-header">
<h2>DELETE USER</h2>
</div>
<div class="modal-body">
<p>Do you realy want to delete the user? </p>
<p>username: ??? </p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">CANCEL</button>
<button type="button" class="btn btn-danger">DELETE</button>
</div>
</div>
</div>
and this is the app.controller
app.controller('UsersController',['$translate', '$scope','$filter', '$http', function($translate,$scope, $filter, $http) {
$scope.users = [];
$http.get('/user').then(function(resp) {
$scope.users = resp.data;
});
$scope.tableConfig = {
columns : [
{
data : 'username'
},
{
data : 'lastname'
},
{
data : 'firstname'
},
{
data : 'supplier',
render : function(data, type, row, meta) {
if (!data || !data.name) {
return '';
}
return data.name;
}
},
{
data : 'role'
},
{
//the edit button
data : 'id',
render : function(data, type, row, meta) {
if (!data || !data) {
return '';
}
return '<a class="btn btn-warning btn-sm btn-block" href=/editUser?userid=' + data + '>' + ($filter('translate')('edit')) + '</a>';
}
},
{
//the delete button
data : 'id',
render : function(data, type, row, meta) {
if (!data || !data) {
return '';
}
return '<button type="button" class="btn btn-danger btn-sm btn-block" id="myDELBtn" data-toggle="modal" data-target="#myModal" >DEL</button>'
}
},
]
}
}]);