我试图通过使用metronic主题为datatable
文件赋值来直接向.js
添加行。但是datatable
没有添加任何值。问题是它没有反映在表上。当调试它时,项目值会显示但不会被添加到表的行数组中。
HTML code:
<!-- BEGIN MAIN CONTENT -->
<div class="row" ng-controller="compctrl">
<div class="col-md-12">
<!-- BEGIN EXAMPLE TABLE PORTLET-->
<div class="portlet box blue-hoki">
<div class="portlet-title">
<div class="caption">
<i class="fa fa-globe"></i>Datatable with TableTools
</div>
<div class="tools">
</div>
</div>
<div class="portlet-body">
<table class="table table-striped table-bordered table-hover " id="sample_1">
<thead>
<tr>
<th>
name
</th>
<th>
strength
</th>
</tr>
</thead>
</table>
</div>
</div>
<!-- END EXAMPLE TABLE PORTLET-->
.js code:
MetronicApp.controller('compctrl', ['$scope',function($scope) {
$scope.$on('$viewContentLoaded', function() {
alert("Controller called!");
var tableData= [{'name':'Infosys Technologies','strength':1000}];
var table=$('sample_1').DataTable();
tableData.forEach(function(item)
{
var row=[];
row.push(item.name);
row.push(item.strength);
table.add(row);
});
table.draw(row);
} );
}]);
答案 0 :(得分:0)
我试图在小提琴中复制这个问题,但不能这样做。所以我写了一个更简单的版本并进行了测试。它正在发挥作用。
var MetronicApp = angular.module('myApp', []);
MetronicApp.controller('compctrl', function($scope) {
alert("Controller called!");
var tableData= [{'name':'Infosys Technologies','strength':1000}];
var table=$('#sample_1').DataTable();
tableData.forEach(function(item)
{
var row=[];
row.push(item.name);
row.push(item.strength);
table.row.add(row).draw(false);
});
});