0

Following is the way im adding rows in jquery datatables from angular

reviewManger.GetUnapprovedReviews().then(function (data) {
    if (data != null) {
        var result = Reviews.Common.MakeValidJSON(data);
        if (result != null) {
            $scope.reviews = result;
            var table = $("#editable");

            var tp = table.DataTable();
            for (var i = 0; i < $scope.reviews.length; i++) {
                tp.row.add([
                    $scope.reviews[i].ID,
                    $scope.reviews[i].AddedOn,
                    $scope.reviews[i].Company.Name,
                    $scope.reviews[i].User.Name,
                    $scope.reviews[i].Description,
                    $sce.trustAsHtml("<span ng-click='EnableDisable(" + $scope.reviews[i].ID + ")>Change</span>")
                ]).draw();
            }
        }
    }
}, function (error) {
});

The problem is i dont see the rendered HTML in last column of all rows in jquery data tables , all other columns are filled in all rows.

How to add html in jQuery data table row?

1
  • how are you binding the trustedHTML in template? Commented Aug 30, 2015 at 17:27

2 Answers 2

1

I had to compile the angular template in order to work Used $compile from angular Following is the code i changed :

  if (result != null) {
                    $scope.reviews = result;
                    var table: any = $("#editable");
                    //table.DataTable();
                    var tp = table.DataTable();

                    for (var i = 0; i < $scope.reviews.length; i++) {
                        var id = $scope.reviews[i].ID;
                        var checked = $scope.reviews[i].Enabled == "1" ? true : false;
                        tp.row.add(
                            [
                                $scope.reviews[i].ID,
                                $scope.reviews[i].AddedOn,
                                $scope.reviews[i].Company.Name,
                                $scope.reviews[i].User.Name,
                                $scope.reviews[i].Description,
                                "<div class='switch'><div class='onoffswitch'><input ng-checked='" + checked+"' class='onoffswitch-checkbox' id= 'stat" + id + "' type= 'checkbox'><label class='onoffswitch-label' for='stat" + id + "'><span class='onoffswitch-inner'></span><span class='onoffswitch-switch'></span></label></div></div>"
                                //"<div class='switch'><div class='onoffswitch'><input checked='' class='onoffswitch- checkbox' id= 'stat" + id + "' type= 'checkbox'><label class='onoffswitch- label' for='stat" + id + "'><span class='onoffswitch- inner'></span><span class='onoffswitch-switch'></span></label></div></div>"
                                //"<button ng-click='EnableDisable(" + $scope.reviews[i].ID + ")'>Change</button>"

                            ]
                            );
                    }

                    tp.draw();

                    $compile(table)($scope); 
                }
Sign up to request clarification or add additional context in comments.

Comments

0

you must bind trusted html with <div ng-bind-html="tp.row[x]"></div> or something like that to get the html replacement. I can't see your markup so it depends. Might benefit you to post the markup.

Comments

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.