2015-07-10 35 views
0

显示数据我有如下我的HTML表格:如何使用Angularjs和数据表在HTML表格

<div> 
    <table datatable="" class="table table-condensed" id="listTable"> 
    <thead> 
     <tr> 
     <th>NAV ID</th> 
     <th>NAV DATE</th> 
     <th>DESCRIPTION</th> 
     <th>AMOUNT</th> 
     <th>ADMIN FEE</th> 
     <th>PURCHASE PRICE</th> 
     <th>POSTED BY</th> 
     </tr> 
    </thead> 
    <tbody> 
     <tr ng-repeat="navs in navs"> 
     <td>{{navs.NAV_ID}}</td> 
     <td>{{navs.NAV_DATE}}</td> 
     <td>{{navs.DESCRIPT}}</td> 
     <td>{{navs.AMOUNT}}</td> 
     <td>{{navs.ADMIN_FEE}}</td> 
     <td>{{navs.P_PRICE}}</td> 
     <td>{{navs.STAFFNAME}}</td> 
     </tr> 
    </tbody> 
    </table> 
</div> 

和我有js脚本来呈现在我的HTML表中的数据。我如何使用datatables插件和js文件。我使用下面的脚本太多加载到我的HTML页面的值。值加载很好,但我坚持,当涉及到数据表中的

angular.module('CrudApp', []). 
config(['$routeProvider', 
    function($routeProvider) { 
    $routeProvider. 
    when('/', { 
     templateUrl: 'assets/templates/list.html', 
     controller: ListCtrl 
    }). 
    when('/addNavs', { 
     templateUrl: 'assets/templates/addNewNav.html', 
     controller: AddCtrl 
    }). 
    otherwise({ 
     redirectTo: '/' 
    }); 
    } 
]); 

function ListCtrl($scope, $http) { 
    $http.get('api/getnavs').success(function(data) { 
    $scope.navs = data; 

    }); 
} 
+0

欢迎StackOverflow的..你创建自定义的指令,如果是的话也请分享代码。 – Madhu

+0

谢谢。我没有创建一个自定义指令。 – Ally

+0

ng-repeat =“导航导航” - 不应该是“导航导航”? – TimoSolo

回答

0

谢谢大家的回答,他们给了我很好的想法来解决任务。我设法弄清楚如何去做。我从this得到了一个想法,我设法想出了适用于我的这段代码。希望它可以帮助有相同问题的人 app.controller('withOptionsCtrl',withOptionsCtrl); 功能withOptionsCtrl($范围,DTOptionsBuilder,DTColumnDefBuilder){

$scope.dtOptions = DTOptionsBuilder.newOptions() 
    .withPaginationType('full_numbers') 
    .withDisplayLength(5) 
    .withDOM('pitrfl'); 
$scope.dtColumnDefs=[ 
DTColumnDefBuilder.newColumnDef(0), 
DTColumnDefBuilder.newColumnDef(1).notVisible, 
DTColumnDefBuilder.newColumnDef(2).notVisible, 
DTColumnDefBuilder.newColumnDef(3).notVisible, 
DTColumnDefBuilder.newColumnDef(4).notVisible, 
DTColumnDefBuilder.newColumnDef(5).notVisible, 
DTColumnDefBuilder.newColumnDef(6).notVisible 
]; 

}

0

你必须写一个后端的Web服务的服务将直接与数据库通信显示数据。

$ http.get( 'API/getnavs')成功(功能(数据){$ = scope.navs数据;

})。

通过使用此服务调用从服务器检索数据。您无法使用前端编程语言(如角JS)访问数据库。

但是前端数据库像袋子DB有机会。

+0

http://blog.brunoscopelliti.com/building-a-restful-web-service-with-angularjs-and-php-more-power-with-resource/ –

+0

我有一个后端Web服务来获取数据来自数据库。我可以在HTML表格上显示数据,但让数据在jQuery数据表中给我一个很难的时间。 – Ally

相关问题