use*_*707 5 angularjs ng-grid smart-table
我是AngularJS和SmartTable的新手......我现在正试图让SmartTable为列进行显示/隐藏切换.从我的承诺SmartTable不这样做,所以我使用ng-Grid显示/隐藏功能...试图遵循这个解决方案: 如何在外部隐藏/显示ng-grid列?
当我实现此解决方案时,我的列没有显示出来.
如何在初始设置时将smartTable列设置为"show"?我想这就是我所缺少的......
这是我的js:
var app = angular.module('myApp', ['smart-table', 'ngGrid']);
app.controller('paginationCtrl', ['$scope', function (scope) {
var nameList = ['Brian', 'Bob', 'Marie', 'Jennifer', 'Frank'],
familyName = ['Smith', 'Miller', 'Patel', 'Jefferson', 'Mendez'];
...
$scope.toggleCol= function(i) {
$scope.gridOptions.$gridScope.columns[i].toggleVisible()
}
scope.itemsByPage=15;
scope.rowCollection = [];
for (var j = 0; j < 200; j++) {
scope.rowCollection.push(createRandomItem());
}
}]);
Run Code Online (Sandbox Code Playgroud)
这是我的HTML:
<body ng-controller="paginationCtrl">
<p>Smart Table Example</p>
<input type="button" value="First Name" ng-click="toggleCol(0)" />
<table class="table table-striped" st-table="rowCollection">
<thead>
<tr>
<th st-sort="firstName">first name</th>
<th st-sort="lastName">last name</th>
<th st-skip-natural="true" st-sort="balance">balance</th>
<th>email</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="row in rowCollection">
<td>{{row.firstName}}</td>
<td>{{row.lastName}}</td>
<td>{{row.balance}}</td>
<td>{{row.email}}</td>
</tr>
</tbody>
<tfoot>
<tr>
<td class="text-center" colspan="5">
<div st-displayed-pages="7" st-items-by-page="itemsByPage" st-pagination=""></div>
</td>
</tr>
</tfoot>
</table>
Run Code Online (Sandbox Code Playgroud)
你可以在我的plunker示例中看到我的整个设置:
http://plnkr.co/edit/6F8NsDdgaWranTXeIQuV?p=preview
谢谢!!
如果其他人试图这样做,我最终没有去ngGrid路线.我能够使用按钮和ng-hide来完成我想要的.对于我的HTML我做了这个:
<button ng-click="firstNameToggle = !firstNameToggle" type="button" class="btn btn-primary">First Name</button>
<button ng-click="lastNameToggle = !lastNameToggle" type="button" class="btn btn-info">Last Name</button>
<button ng-click="balanceToggle = !balanceToggle" type="button" class="btn btn-default">Balance</button>
<button ng-click="emailToggle = !emailToggle" type="button" class="btn btn-success">Email</button>
</div>
<table class="table table-hover table-striped" st-table="rowCollection">
<thead>
<tr>
<th ng-hide="firstNameToggle" st-sort="firstName">first name</th>
<th ng-hide="lastNameToggle"st-sort="lastName">last name</th>
<th ng-hide="balanceToggle"st-skip-natural="true" st-sort="balance">balance</th>
<th ng-hide="emailToggle">email</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="row in rowCollection">
<td ng-hide="firstNameToggle">{{row.firstName}}</td>
<td ng-hide="lastNameToggle">{{row.lastName}}</td>
<td ng-hide="balanceToggle">{{row.balance}}</td>
<td ng-hide="emailToggle">{{row.email}}</td>
</tr>
</tbody>
Run Code Online (Sandbox Code Playgroud)
和我的js:
app.controller('basicsCtrl', ['$scope', function (scope) {
scope.rowCollection = [
{firstName: 'Laurent', lastName: 'Renard', birthDate: new Date('1987-05-21'), balance: 102, email: 'whatever@gmail.com'},
{firstName: 'Blandine', lastName: 'Faivre', birthDate: new Date('1987-04-25'), balance: -2323.22, email: 'oufblandou@gmail.com'},
{firstName: 'Francoise', lastName: 'Frere', birthDate: new Date('1955-08-27'), balance: 42343, email: 'raymondef@gmail.com'}
];
scope.getters={
firstName: function (value) {
//this will sort by the length of the first name string
return value.firstName.length;
}
}
scope.firstNameToggle = "false";
scope.lastNameToggle = "false";
scope.balanceToggle = "false";
scope.emailToggle = "false";
}]);
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
14638 次 |
最近记录: |