Angualrjs和bootstrap相結合實現資料表格table,angualrjsbootstrap

來源:互聯網
上載者:User

Angualrjs和bootstrap相結合實現資料表格table,angualrjsbootstrap

AngularJS的資料表格

需要使用angualarjs、bootstrap、dirPagination.js

1.html部分

<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml" data-ng-app="app"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>  <title>angularjs的資料表格</title>  <link rel="stylesheet" href="css/bootstrap-3.0.0/css/bootstrap.css" rel="external nofollow" />  <link href="css/special.css" rel="external nofollow" rel="stylesheet" />  <script src="js/angular-1.3.0.js"></script>  <script src="vendor/dirPagination.js"></script>  <script src="js/app/angularjsTable.js"></script></head><body>  <form ng-controller="tableCtrl as aly">    <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 <= 0">            <td colspan="5" style="text-align: center;">還沒有資料</td>          </tr>          <tr dir-paginate="user in aly.users|itemsPerPage:aly.itemsPerPage" total-items="aly.total_count">            <td>{{user.code}}</td>            <td>{{user.name}}</td>            <td>{{user.version}}</td>            <td>{{user.status}}</td>            <td>              <a class="sp-color-blue">安 裝</a>|              <a class="sp-color-green">查 看</a>            </td>          </tr>          <!--<tr>            <td>asd1234ddd</td>            <td>員工管理</td>            <td>v2.0.1</td>            <td>已啟用</td>            <td><a ui-sref="app.apply_view" class="ligblue">查 看</a></td>          </tr>-->        </tbody>      </table>      <dir-pagination-controls max-size="8"        direction-links="true"        boundary-links="true"        on-page-change="aly.getData(newPageNumber)">              </dir-pagination-controls>    </div>  </form></body></html>

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,希望對大家有所協助,如果大家有任何疑問請給我留言,小編會及時回複大家的。在此也非常感謝大家對幫客之家網站的支援!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.