1

I am using the the bootstrap datatable with my angularjs application and in this am creating the link in a column dynamically by using the following code but i am unable to fire its ng-click function.If i return the simple html in the formatter fields its not firing and when i use $compile to return then it shows the object in that column.Its showing correctly in the datatable the problem is only its ng-click is not firing .How can i do it?

$scope.matterTableControl = {
options: {
queryParams: queryParams,
toolbar: "#get",
url: intakeAppFactory.getUserMatters(),
sidePagination: 'server',
showColumns: true,
clickToSelect: false,
maintainSelected: true,
columns: [
{
field: 'Name',
title: 'Matter',
align: 'center',
valign: 'bottom',
sortable: false,
formatter: matterNameFormatter
}]
}
};

function matterNameFormatter(value, row, index) {
return '<a href="javascript:void(0)"  ng-click="showValue(\'' + row.MatterId + '\')">' + value + '</a>');
}
2
  • Why the anchor tag is not properly closed? <a href="javascript:void(0)" ng-click="showValue(\'' + row.MatterId + '\' Commented Feb 2, 2016 at 4:29
  • its properly closed its just typing mistake when i am posting it here.. its showing correctly in the datatable but its ng-click is not working :( Commented Feb 2, 2016 at 4:30

1 Answer 1

1

You need to $compile the html string and bind $scope to it.

function matterNameFormatter(value, row, index) {
    var newElement =  angular.element('<a href="javascript:void(0)"  ng-click="showValue(\'' + row.MatterId + '\')">' + value + '</a>'));
    $compile(newElement)($scope);
    return newElement;
}

You have to use $compile to compile the new element and bind the $scope to it.

P.S. I am assuming all of the code provided is inside the controller and both $compile and $scope will be accessible from matterNameFormatter

Sign up to request clarification or add additional context in comments.

7 Comments

its returing [object][object]
@ManjitSingh what datatable plugin are you using?
@ManjitSingh Can you make a js-fiddle?
i have never made this but i will try..... Please help if you found anything its urgent :(
|

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.