[英]Sorting is not working in smart table angular js
Smart table sorting is not working for some reason after using as custom directive. 用作自定义指令后,智能表排序由于某些原因无法正常工作。 Can you help me what I did wrong?
你能帮我做错什么吗?
My code http://plnkr.co/edit/mzPifIAT0RTd63rIYJsi?p=preview 我的代码http://plnkr.co/edit/mzPifIAT0RTd63rIYJsi?p=preview
Here is my view, HTML and js Code: 这是我的观点,HTML和js代码:
View 视图
<div ng-controller="ctrl1 as one">
<ltcg-table options="one.rowCollection"></ltcg-table>
</div>
<div ng-controller="ctrl2 as two">
<ltcg-table options="two.rowCollection"></ltcg-table>
</div>
Grid HTML 网格HTML
<table st-table="rowCollection" class="table table-striped">
<thead>
<tr>
<th st-sort="getters.firstName">first name</th>
<th st-sort="lastName">last name</th>
<th st-sort="birthDate">birth date</th>
<th st-sort="balance">balance</th>
<th>email</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="row in options">
<td>{{row.firstName}}</td>
<td>{{row.lastName}}</td>
<td>{{row.birthDate}}</td>
<td>{{row.balance}}</td>
<td>{{row.email}}</td>
</tr>
</tbody>
</table>
js js
(function () {
var myApp = angular.module('myApp', ['smart-table']);
function one() {
this.rowCollection = [
{firstName: 'Laurent', lastName: 'Renard', birthDate: 4, balance: 102, email: 'whatever@gmail.com'},
{firstName: 'Blandine', lastName: 'Faivre', birthDate: 5, balance: -2323.22, email: 'oufblandou@gmail.com'},
{firstName: 'Francoise', lastName: 'Frere', birthDate: 4, balance: 42343, email: 'raymondef@gmail.com'}
];
//alert($scope.gridOptions.columnDefs[1].name);
//alert($scope.gridOptions);
};
function two() {
this.rowCollection = [
{firstName: 'test2', lastName: 'Renard', birthDate: new Date('1987-05-21'), balance: 102, email: 'whatever@gmail.com'},
{firstName: 'test2', lastName: 'Faivre', birthDate: new Date('1987-04-25'), balance: -2323.22, email: 'oufblandou@gmail.com'},
{firstName: 'test2', lastName: 'Frere', birthDate: new Date('1955-08-27'), balance: 42343, email: 'raymondef@gmail.com'}
];
//alert($scope.gridOptions.columnDefs[1].name);
//alert($scope.gridOptions);
};
myApp.directive('ltcgTable', function() {
return {
restrict: 'E',
transclude: true,
scope: {
'options': '='
},
templateUrl: "ltcg-table.html",
link: function(scope, element, attr) {
scope.rowCollection = scope.options;
}
}
});
myApp.controller('ctrl1', one)
myApp.controller('ctrl2', two)
})();
Ok the issue was two things 好的,问题是两件事
You need to use st-safe-src 您需要使用st-safe-src
<table st-safe-src="rowCollection" st-table="displayCollection" class="table table-striped">
And your row ng-repeat needs to be on the displayCollection
并且您的行ng-repeat需要在
displayCollection
<tr ng-repeat="row in displayCollection">
You don't need to initialise displayCollection
您不需要初始化
displayCollection
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.