Reputation: 10319
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?
Upvotes: 0
Views: 2246
Reputation: 10319
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);
}
Upvotes: 1
Reputation: 2607
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.
Upvotes: 0