javascript - 智能表.js : pagination and filter not working

标签 javascript angularjs pagination smart-table

目前我正在研究 Smart-table.js ,需要以下功能,

  • 从网络服务中读取 JSON 数据
  • 创建带分页和过滤器的表格
  • 过滤器可以在单列或全局上

我阅读了 Smart-table.js 的所有文档并根据我的要求创建了示例,可在 Plunker 中找到。

angular.module('myApp',['smart-table'])
.controller('MainCtrl',['$scope','$http',function(scope,http)
{
    scope.rowCollection = [];
    http.get("https://api.myjson.com/bins/mr6e")
    .success(function(response) 
    {
        scope.rowCollection=response.d;
    });
    scope.displayedCollection = [].concat(scope.rowCollection);
    scope.itemsByPage=5;
    
    scope.columnCollection = [
        {label: 'Member ID', map: 'memberID'},
        {label: 'Member Name', map: 'memberName'},
        {label: 'Date Time', map: 'dateTime'},
        {label: 'Balance', map: 'balance'}, 
        {label: 'Amount', map: 'amount'},
        {label: 'Remarks', map: 'remarks'}
    ];
    
    
}])
     

但我没有得到预期的输出(分页和过滤器不工作)。请问有人可以建议我解决方案吗?

最佳答案

如果您删除 scope.displayedCollection 行并将集合设置为 html View 中的 rowCollection,它将正常工作。查看 Plunkr。

Plunkr

angular.module('myApp',['smart-table'])
    .controller('MainCtrl',['$scope','$http',function(scope,http)
    {
        scope.rowCollection = [];
        http.get("https://api.myjson.com/bins/mr6e")
        .success(function(response) 
        {
            scope.rowCollection=response.d;
        });
        scope.itemsByPage=5;

        scope.columnCollection = [
            {label: 'Member ID', map: 'memberID'},
            {label: 'Member Name', map: 'memberName'},
            {label: 'Date Time', map: 'dateTime'},
            {label: 'Balance', map: 'balance'}, 
            {label: 'Amount', map: 'amount'},
            {label: 'Remarks', map: 'remarks'}
        ];


}])
.directive('stExport',function(){
  return {
      require:'^stTable',
      link:function(scope, element, attr,ctrl){
      element.bind('click',function(){
      alert(ctrl.getFilteredCollection().length);

  })
}
}

});

关于javascript - 智能表.js : pagination and filter not working,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32401520/

相关文章:

javascript - D3 变焦设置

javascript - 使用 AngularJS 从 JSON 响应获取图像 url

javascript - 如何使用knockout.js组件正确创建分页?

javascript - Angularjs - 文本区域自动增长

javascript - 如何在 AJAX "paginated" View 中保持复选框选中状态?

ios - Xcode、UIscrollView 和分页

javascript - Gulp less 未正确处理包括未定义的包含变量

javascript - 实时聊天 Jquery 插件 tawk.to 不可见

javascript - 数组符号运算顺序

javascript - 查找提供继承属性的对象