我对AngularJs很陌生并试图"包装"指令中的Smart-Table插件。 我可以获得行,但分页没有显示
目前这就是我所做的。
app.directive('grid', [ function () {
return {
restrict: 'E',
replace: true,
template: function (element, attrs) {
return '<table class="table table-striped">'
+ '<thead>'
+ ' <tr>'
+ '<th st-ratio="20" st-sort="Team">Team</th>'
+ '<th st-ratio="20" st-sort="TeamFreq">Team Freq</th>'
+ '<th st-ratio="10" st-sort="TeamSac">Team Sac</th>'
+ '<th st-ratio="30" st-sort="Priority">Priority</th>'
+ '</tr>'
+ '</thead>'
+ '<tbody>'
+ '<tr ng-repeat="row in dataset">'
+ ' <td>{{row.firstName}}</td>'
+ '<td>{{row.lastName | uppercase}}</td>'
+ '<td>{{row.age}}</td>'
+ '<td>{{row.email}}</td>'
+ '</tr>'
+ '</tbody>'
+ '<tfoot>'
+ '<tr>'
+ '<td colspan="4" class="text-center">'
+ '<div class="pagination pagination-xs m-top-none pull-right" st-pagination="1" st-items-by-page="itemsByPage" st-displayed-pages="4"></div>'
+ '</td>'
+ '</tr>'
+ '</tfoot>'
+ '</table>';
},
scope: {
},
controller: function ($scope) {
},
link: function (scope, elem, attrs) {
var nameList = ['Pierre', 'Pol', 'Jacques', 'Robert', 'Elisa'], familyName = ['Dupont', 'Germain', 'Delcourt', 'bjip', 'Menez'];
function createRandomItem() {
var
firstName = nameList[Math.floor(Math.random() * 4)],
lastName = familyName[Math.floor(Math.random() * 4)],
age = Math.floor(Math.random() * 100),
email = firstName + lastName + '@@whatever.com',
balance = Math.random() * 3000;
return {
firstName: firstName,
lastName: lastName,
age: age,
email: email,
balance: balance
};
}
scope.rowCollection = [];
for (var j = 0; j < 10; j++) {
scope.rowCollection.push(createRandomItem());
}
scope.dataset = [].concat(scope.rowCollection);
}
};
}]);
我的html包含此标记
<grid st-table="dataset"></grid>
此代码只是一个测试,数据将使用服务传递..模板将是动态的。 我需要一些帮助: - )
由于
答案 0 :(得分:1)
前几天,当我在指令中使用智能表时,我无法显示分页。事实证明它与指令无关,我只是从GitHub中提取/更新到最新版本的smart-table,这一切都奏效了。我开始看看发生了什么变化但是进行了跟踪并转向更有成效的事情,很高兴现在正在工作。 看似工作正常的版本标记为1.4.2。
但是,对于来自服务的动态数据,我认为您还需要查看st-safe-src属性。虽然我对整个Angular / smart-table业务也很陌生。
答案 1 :(得分:0)
我相信你必须匹配st-table值和st-pagination值才能显示分页。