我正在用AngularJS和Bootstrap 3创建一个应用程序。我想显示一个有数千行的表/网格。什么是AngularJS & Bootstrap中最好的控件,具有排序、搜索、分页等功能。
当前回答
你可以使用bootstrap类并使用ng-repeat指令建立一个表
例子:
angular.module('App', []); function ctrl($scope) { $scope.items = [ ['A', 'B', 'C'], ['item1', 'item2', 'item3'], ['item4', 'item5', 'item6'] ]; } <link href="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet" /> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> <div ng-app="App"> <div ng-controller="ctrl"> <table class="table table-bordered"> <thead> <tr> <th ng-repeat="itemA in items[0]">{{itemA}}</th> </tr> </thead> <tbody> <tr> <td ng-repeat="itemB in items[1]">{{itemB}}</td> </tr> <tr> <td ng-repeat="itemC in items[2]">{{itemC}}</td> </tr> </tbody> </table> </div> </div>
生活例子: http://jsfiddle.net/choroshin/5YDJW/5/
更新:
或者你可以尝试流行的ng-grid, ng-grid很适合排序、搜索、分组等,但我还没有在大规模数据上测试过。
其他回答
对于“数千行”,您最好的选择显然是进行服务器端分页。当我查看不同的AngularJs表格/网格选项时,有三个明显的最爱:
ng-grid ng-table Smart-Table
这三个都很好,但实现方式不同。你选择哪一个可能更多的是基于个人喜好,而不是其他因素。
ng-grid可能是最著名的,因为它与angular-ui有关联,但我个人更喜欢ng-table,我真的很喜欢他们的实现和你使用它的方式,他们有很好的文档和示例,并且正在积极改进。
正如在其他答案中提到的:对于具有搜索功能的表,选择和分页“ng-grid”是最好的选择。我将提到一些我遇到的事情,这些事情在执行时可能会有用:
设置env:
http://www.json-generator.com/生成JSON数据。它是一个非常酷的工具,可以获得示例数据集,从而加快开发速度。 您可以检查这个活塞为您的实现。我已经修改包括:搜索,选择和分页 http://plnkr.co/edit/gJPBz0pVxGzKlI8MGOit?p=preview
你可以查看这篇关于智能表格的教程,给出了你需要的所有信息: http://lorenzofox3.github.io/smart-table-website/
下一个问题是引导3: 不完全是,但这个模板看起来不错。 -你可以使用https://github.com/angular-ui/bootstrap/tree/master/template所有的模板都写得很好。
我可以继续介绍如何将bootstrap 3转换为angularjs,但它已经在以下链接中提到:
引导3兼容当前的AngularJS引导指令? https://github.com/angular-ui/bootstrap/issues/331
请注意,关于智能桌,你必须检查它是否为你的角版本做好了准备
Adapt-Strap。这是小提琴。
它非常轻,并具有动态行高。
<ad-table-lite table-name="carsForSale"
column-definition="carsTableColumnDefinition"
local-data-source="models.carsForSale"
page-sizes="[7, 20]">
</ad-table-lite>
剑道网格和Wijmo一样好。我知道Kendo的数据源有Angular绑定,Wijmo也有Angular插件。不过,它们都不是免费的。
你可以使用bootstrap类并使用ng-repeat指令建立一个表
例子:
angular.module('App', []); function ctrl($scope) { $scope.items = [ ['A', 'B', 'C'], ['item1', 'item2', 'item3'], ['item4', 'item5', 'item6'] ]; } <link href="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet" /> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> <div ng-app="App"> <div ng-controller="ctrl"> <table class="table table-bordered"> <thead> <tr> <th ng-repeat="itemA in items[0]">{{itemA}}</th> </tr> </thead> <tbody> <tr> <td ng-repeat="itemB in items[1]">{{itemB}}</td> </tr> <tr> <td ng-repeat="itemC in items[2]">{{itemC}}</td> </tr> </tbody> </table> </div> </div>
生活例子: http://jsfiddle.net/choroshin/5YDJW/5/
更新:
或者你可以尝试流行的ng-grid, ng-grid很适合排序、搜索、分组等,但我还没有在大规模数据上测试过。
推荐文章
- AngularJS控制器的生命周期是什么?
- $destroy是否删除事件监听器?
- Bootstrap抛出Uncaught错误:Bootstrap的JavaScript需要jQuery
- 用布尔值将单选按钮绑定到模型
- AngularJS只适用于单页应用程序吗?
- angular.js中的内联条件
- 如何突出显示当前菜单项?
- 如何使用AngularJS获取url参数
- Twitter Bootstrap 3 Sticky Footer
- angularjs中的compile函数和link函数有什么区别
- Ng-repeat结束事件
- 大Glyphicons
- 缓存一个HTTP 'Get'服务响应在AngularJS?
- 从ng-click获取原始元素
- Angular JS:当我们已经有了具有作用域的指令控制器时,指令的link函数还需要什么?