这篇文章主要介绍了Angualrjs和bootstrap相结合实现数据表格table,代码简单易懂,非常不错,具有参考借鉴价值,需要的朋友可以参考下
AngularJS的数据表格
需要使用angualarjs、bootstrap、dirPagination.js
效果图:
1.html部分
<title>angularjs的数据表格</title> <div class="sp-page-content"> <div class="sp-page-title"> angularjs的数据表格 </div><table class="sp-grid"> <thead> <tr> <th style="width: 20%">应用代码</th><th style="width: 20%">应用名称</th><th style="width: 20%">版本</th><th style="width: 20%">状态</th><th style="width: 20%">操作</th></tr></thead><tbody id="myApplyTable"> <tr ng-show="aly.users.length <td colspan="5" style="text-align: center">还没有数据</td></tr><tr> <td>{{user.code}}</td><td>{{user.name}}</td><td>{{user.version}}</td><td>{{user.status}}</td><td> 安 装| 查 看</td></tr><!--<tr> <td>asd1234ddd</td> <td>员工管理</td> <td>v2.0.1</td> <td>已启用</td> <td>查 看</td> </tr>--></tbody></table> </div>
2.angularjsTable.js部分
'use strict'; var app = angular.module('app', [ 'angularUtils.directives.dirPagination' ]); app.controller('tableCtrl', ['$http', function ($http) { var self = this; //数据表格的控制器,动态加载table表格数据 self.users = []; //declare an empty array self.pageno = 1; // initialize page no to 1 self.total_count = 0; self.itemsPerPage = 10; //this could be a dynamic value from a drop down self.getData = function (pageno) { // This would fetch the data on page change. //In practice this should be in a factory. self.pageno = pageno; self.users = []; $http({ method: 'get', url: 'json/myApply.txt', data: { pagesize: self.itemsPerPage, pageno: self.pageno } }).success(function (response) { self.users = response.data; //ajax request to fetch data into self.data self.total_count = response.total_count; }); }; self.getData(self.pageno); //数据表格的控制器 end }]);
3.json数据部分 myApply.txt
{ "data":[ { "id":"1", "code":"dheu22102d", "name":"项目管理", "version":"v1.0.1", "status":"未启用" }, { "id":"2", "code":"asd1234ddd", "name":"员工管理", "version":"v2.0.1", "status":"已启用" } ], "total_count": 22 }
以上就是Angualrjs和bootstrap相结合实现数据表格table的来源gao.dai.ma.com搞@代*码网详细内容,更多请关注gaodaima搞代码网其它相关文章!