Skip to content

Commit

Permalink
RenderWith with data object in ng-click #145
Browse files Browse the repository at this point in the history
  • Loading branch information
l-lin committed Sep 4, 2015
1 parent 5488f98 commit 042684b
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions demo/advanced/bindAngularDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ function BindAngularDirectiveCtrl($scope, $compile, DTOptionsBuilder, DTColumnBu
vm.edit = edit;
vm.delete = deleteRow;
vm.dtInstance = {};
vm.persons = {};
vm.dtOptions = DTOptionsBuilder.fromSource('data1.json')
.withPaginationType('full_numbers')
.withOption('createdRow', createdRow);
Expand All @@ -19,14 +20,14 @@ function BindAngularDirectiveCtrl($scope, $compile, DTOptionsBuilder, DTColumnBu
.renderWith(actionsHtml)
];

function edit(id) {
vm.message = 'You are trying to edit the row with ID: ' + id;
function edit(person) {
vm.message = 'You are trying to edit the row: ' + JSON.stringify(person);
// Edit some data and call server to make changes...
// Then reload the data so that DT is refreshed
vm.dtInstance.reloadData();
}
function deleteRow(id) {
vm.message = 'You are trying to remove the row with ID: ' + id;
function deleteRow(person) {
vm.message = 'You are trying to remove the row: ' + JSON.stringify(person);
// Delete some data and call server to make changes...
// Then reload the data so that DT is refreshed
vm.dtInstance.reloadData();
Expand All @@ -36,10 +37,11 @@ function BindAngularDirectiveCtrl($scope, $compile, DTOptionsBuilder, DTColumnBu
$compile(angular.element(row).contents())($scope);
}
function actionsHtml(data, type, full, meta) {
return '<button class="btn btn-warning" ng-click="showCase.edit(' + data.id + ')">' +
vm.persons[data.id] = data;
return '<button class="btn btn-warning" ng-click="showCase.edit(showCase.persons[' + data.id + '])">' +
' <i class="fa fa-edit"></i>' +
'</button>&nbsp;' +
'<button class="btn btn-danger" ng-click="showCase.delete(' + data.id + ')">' +
'<button class="btn btn-danger" ng-click="showCase.delete(showCase.persons[' + data.id + '])")">' +
' <i class="fa fa-trash-o"></i>' +
'</button>';
}
Expand Down

0 comments on commit 042684b

Please sign in to comment.