Angularjs 表格插件的使用


對於相關的table組件可以使用:UI Grid (ng-grid),ng-table,smart table,Angular-Datatables,tablelite,kendo-ui中的grid。相關的介紹可以參考http://zhenghaoju700.blog.163.com/blog/static/135859518201521343938228/

對於一般的項目來說 簡單的顯示表格用bootstrap的相關插件或者自己寫也行,對於分頁,我嘗試了用smart-tablel這個組件來寫的,效果感覺還是不錯的。其他的組件本人還沒有親自試驗過。嘿嘿...

效果截圖:

下面是實現的主要方式:

1.安裝

1 bower install angular-smart-table

2.加入module

1 angular.module('myApp',['smart-table']

3.HTML

 1 <table st-table="rowCollection" class="table table-striped">
 2         <thead>
 3         <tr>
 4             <th st-sort="firstName">first name</th>
 5             <th st-sort="lastName">last name</th>
 6             <th st-sort="birthDate">birth date</th>
 7             <th st-sort="balance">balance</th>
 8             <th>email</th>
 9         </tr>
10         <tr>
11             <th>
12                 <input st-search="'firstName'" placeholder="search for firstname" class="input-sm form-control" type="search"/>
13             </th>
14             <th colspan="4">
15                 <input st-search placeholder="global search" class="input-sm form-control" type="search"/>
16             </th>
17         </tr>
18         </thead>
19         <tbody>
20         <tr ng-repeat="row in rowCollection">
21             <td>{{row.firstName | uppercase}}</td>
22             <td>{{row.lastName}}</td>
23             <td>{{row.birthDate | date}}</td>
24             <td>{{row.balance | currency}}</td>
25             <td><a ng-href="mailto:{{row.email}}">email</a></td>
26         </tr>
27         </tbody>
28         <tfoot>
29             <tr>
30                 <td colspan="5" class="text-center">
31                     <div st-pagination="" st-items-by-page="itemsByPage" st-displayed-pages="7"></div>
32                 </td>
33             </tr>
34         </tfoot>
35     </table>

4.JavaScript

 1 app.controller('paginationCtrl', ['$scope', function (scope) {
 2     var
 3         nameList = ['Pierre', 'Pol', 'Jacques', 'Robert', 'Elisa'],
 4         familyName = ['Dupont', 'Germain', 'Delcourt', 'bjip', 'Menez'];
 5 
 6     function createRandomItem() {
 7         var
 8             firstName = nameList[Math.floor(Math.random() * 4)],
 9             lastName = familyName[Math.floor(Math.random() * 4)],
10             age = Math.floor(Math.random() * 100),
11             email = firstName + lastName + '@whatever.com',
12             balance = Math.random() * 3000;
13 
14         return{
15             firstName: firstName,
16             lastName: lastName,
17             age: age,
18             email: email,
19             balance: balance
20         };
21     }
22 
23         scope.itemsByPage=15;
24 
25     scope.rowCollection = [];
26     for (var j = 0; j < 200; j++) {
27         scope.rowCollection.push(createRandomItem());
28     }
29 }]);

感覺其實也很簡單,我也只是初學,給自己留個備忘吧,還有其他的組件,慢慢學着使用。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM