0

got a problem with ng-click on angular datatables. I'm using https://l-lin.github.io/angular-datatables

Here is my code

    $scope.dtOptions = DTOptionsBuilder.fromFnPromise(function(){
        return $resource(APIROOT + 'categories').query().$promise;
    })
        .withOption('order', [0, "asc"]);

    $scope.dtColumns = [
        DTColumnBuilder.newColumn('id', 'ID').withOption('searchable', false),
        DTColumnBuilder.newColumn('name', 'Name'),
        DTColumnBuilder.newColumn('', 'Actions').renderWith(function (data, type, full, meta) {
            return '<a class="btn btn-default btn-xs" href="#/edit/' + full.id + '"><i class="fa fa-pencil"></i></a> ' +
                '<button class="btn btn-danger btn-xs" ng-click="deleteItem(' + full.id + ')"><i class="fa fa-trash"></i></button>';

        })

    ];

    $scope.deleteItem = function (id) {
        alert('delete')
    }

delete button is not working.

Is there anything wrong with the code?

4
  • 1
    you need to $compile it. Commented Oct 3, 2015 at 7:43
  • Hi, i tried put that. but not working. :| Commented Oct 3, 2015 at 9:29
  • check js example - l-lin.github.io/angular-datatables/#/bindAngularDirective Commented Oct 3, 2015 at 10:30
  • @YOU Thanks. I missed this option .withOption('createdRow', function(row, data, dataIndex) { // Recompiling so we can bind Angular directive to the DT $compile(angular.element(row).contents())($scope); }) Commented Oct 3, 2015 at 10:38

1 Answer 1

3
 $scope.dtOptions = DTOptionsBuilder.fromFnPromise(function(){
        return $resource(APIROOT + 'categories').query().$promise;
    })
.withOption('createdRow', createdRow)
        .withOption('order', [0, "asc"]);
function createdRow(row, data, dataIndex) {
        // Recompiling so we can bind Angular directive to the DT
        $compile(angular.element(row).contents())($scope);
console.log("test");
    }
//now ur deleteItem function is complied and it'll work.
 $scope.deleteItem = function (id) {
        alert('delete')
    }
Sign up to request clarification or add additional context in comments.

1 Comment

In addition to your code, can you please explain what you did and why it works.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.