如何在jquery中传递html数据表的行添加功能
How to pass html in jquery datatables row add function
下面是我从angular向jquery数据表中添加行的方法
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) {
});
问题是我没有看到在所有行的最后一列呈现HTML 在jquery数据表中,所有其他列都填充在所有行。
如何在jQuery数据表行添加html ?
我必须编译angular模板才能工作使用了$compile from angular以下是我修改的代码:
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);
}
您必须将受信任的html与<div ng-bind-html="tp.row[x]"></div>
或类似的东西绑定以获得html替换。我看不到你的加价,所以要视情况而定。把标记贴出来可能对你有好处。
相关文章:
- 将单击事件添加到数据表
- 如何根据某些条件向可编辑的jquery数据表添加或删除按钮
- 如何将输入数据(许多数据)添加到同一页面的下表中
- 将索引列添加到数据表
- 数据表1.8.0添加服务器参数无效
- JQuery 数据表添加新行,如果该行已经存在,请将其删除并为该 ID 插入新行
- 数据表添加多个子行
- Jquery-向数据表添加超链接
- jQuery数据表添加列的条件
- 数据表添加具有特殊数据字段的行
- jQuery数据表添加类到tr
- 数据表添加/删除数据到文本区域
- 使用slideDown()向jquery数据表添加一行
- 向数据表添加额外的列
- JQuery数据表:添加columnDefs后无法对列进行排序
- 动态地为jQuery数据表添加输入控件
- 数据表:添加行并检查添加的行's索引
- jquery数据表添加未定义的行
- Jquery数据表添加额外的列
- jQuery数据表-添加行不工作