首页 > 建站教程 > JS、jQ、TS >  Angualrjs和bootstrap相结合实现数据表格table_Angular正文

Angualrjs和bootstrap相结合实现数据表格table_Angular

AngularJS的数据表格

需要使用angualarjs、bootstrap、dirPagination.js

效果图:

1.html部分

01<!DOCTYPE html>
02<html xmlns="http://www.w3.org/1999/xhtml" data-ng-app="app">
03<head>
04<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
05  <title>angularjs的数据表格</title>
06  <link rel="stylesheet" href="css/bootstrap-3.0.0/css/bootstrap.css" rel="external nofollow" />
07  <link href="css/special.css" rel="external nofollow" rel="stylesheet" />
08  <script src="js/angular-1.3.0.js"></script>
09  <script src="vendor/dirPagination.js"></script>
10  <script src="js/app/angularjsTable.js"></script>
11</head>
12<body>
13  <form ng-controller="tableCtrl as aly">
14    <div class="sp-page-content">
15      <div class="sp-page-title">
16        angularjs的数据表格
17      </div>
18      <table class="sp-grid">
19        <thead>
20          <tr>
21            <th style="width: 20%;">应用代码</th>
22            <th style="width: 20%;">应用名称</th>
23            <th style="width: 20%;">版本</th>
24            <th style="width: 20%;">状态</th>
25            <th style="width: 20%;">操作</th>
26          </tr>
27        </thead>
28        <tbody id="myApplyTable">
29          <tr ng-show="aly.users.length <= 0">
30            <td colspan="5" style="text-align: center;">还没有数据</td>
31          </tr>
32          <tr dir-paginate="user in aly.users|itemsPerPage:aly.itemsPerPage" total-items="aly.total_count">
33            <td>{{user.code}}</td>
34            <td>{{user.name}}</td>
35            <td>{{user.version}}</td>
36            <td>{{user.status}}</td>
37            <td>
38              <a class="sp-color-blue">安 装</a>|
39              <a class="sp-color-green">查 看</a>
40            </td>
41          </tr>
42          <!--<tr>
43            <td>asd1234ddd</td>
44            <td>员工管理</td>
45            <td>v2.0.1</td>
46            <td>已启用</td>
47            <td><a ui-sref="app.apply_view" class="ligblue">查 看</a></td>
48          </tr>-->
49        </tbody>
50      </table>
51      <dir-pagination-controls max-size="8"
52        direction-links="true"
53        boundary-links="true"
54        on-page-change="aly.getData(newPageNumber)">
55              </dir-pagination-controls>
56    </div>
57  </form>
58</body>
59</html>

2.angularjsTable.js部分

01'use strict';
02var app = angular.module('app', [ 
03  'angularUtils.directives.dirPagination'
04]);
05app.controller('tableCtrl', ['$http', function ($http) {
06  var self = this;
07  //数据表格的控制器,动态加载table表格数据
08  self.users = []; //declare an empty array
09  self.pageno = 1; // initialize page no to 1
10  self.total_count = 0;
11  self.itemsPerPage = 10; //this could be a dynamic value from a drop down
12  self.getData = function (pageno) { // This would fetch the data on page change.
13    //In practice this should be in a factory.
14    self.pageno = pageno;
15    self.users = [];
16    $http({
17      method: 'get',
18      url: 'json/myApply.txt',
19      data: { pagesize: self.itemsPerPage, pageno: self.pageno }
20    }).success(function (response) {
21      self.users = response.data; //ajax request to fetch data into self.data
22      self.total_count = response.total_count;
23    });
24  };
25  self.getData(self.pageno);
26  //数据表格的控制器 end
27}]);

3.json数据部分 myApply.txt

01
02  "data":[
03   {
04  "id":"1",
05"code":"dheu22102d",
06"name":"项目管理",
07"version":"v1.0.1",
08"status":"未启用"
09 },
10 {
11  "id":"2",
12"code":"asd1234ddd",
13"name":"员工管理",
14"version":"v2.0.1",
15"status":"已启用"
16 }
17],
18"total_count": 22
19}

以上所述是小编给大家介绍的Angualrjs和bootstrap相结合实现数据表格table,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!