【问题标题】:BootstrapTable AngularJS extension with data loaded async not working带有异步加载数据的 BootstrapTable AngularJS 扩展不起作用
【发布时间】:2017-10-17 16:17:30
【问题描述】:

我正在使用来自 here 的 BootstrapTable AangularJS 扩展

this plnkr 展示了使用 with extension 的示例。但是该示例使用了在呈现表格之前生成的静态数据。但我试图让它与动态加载的数据一起工作(假设 ajax 请求)。但这不起作用。数据未呈现。

Plnkr example with data loaded async

angular.module('app', ['bsTable'])
    .controller('MainController', function ($scope, $timeout) {

function makeRandomRows () {
    var rows = [];
    for (var i = 0; i < 500; i++) {
        rows.push(
          {
            index: i,
            id: 'row ' + i,
            name: 'GOOG' + i,
            flagImage: '4'
        }
        );
    }
    return rows;
}

$timeout(function(){
    console.log("timedout");
      $scope.bsTableControl.data  = makeRandomRows({ workspace: "test"});
}, 2000);

    var rows = makeRandomRows();

    $scope.bsTableControl = {
        options: {
            data: [],
            rowStyle: function (row, index) {
                return { classes: 'none' };
            },
            cache: false,
            height: 400,
            striped: true,
            pagination: true,
            pageSize: 10,
            pageList: [5, 10, 25, 50, 100, 200],
            search: true,
            showColumns: true,
            showRefresh: false,
            minimumCountColumns: 2,
            clickToSelect: false,
            showToggle: true,
            maintainSelected: true,
            columns: [{
                field: 'state',
                checkbox: true
            }, {
                field: 'index',
                title: '#',
                align: 'right',
                valign: 'bottom',
                sortable: true
            }, {
                field: 'id',
                title: 'Item ID',
                align: 'center',
                valign: 'bottom',
                sortable: true
            }, {
                field: 'name',
                title: 'Item Name',
                align: 'center',
                valign: 'middle',
                sortable: true
            }, {
                field: 'flag',
                title: 'Flag',
                align: 'center',
                valign: 'middle'
            }]
        }
    };

 });

<body ng-controller="MainController">
  <h1>Angular bsTable</h1>
  <div>
    <table bs-table-control="bsTableControl"></table>
  </div>

</body>

感谢您的帮助。

【问题讨论】:

    标签: angularjs bootstrap-table


    【解决方案1】:

    我想出了解决办法。我只需要在加载数据后执行 bsTable 初始化代码,而不是之前进行初始化。

    Updated plnkr

    $timeout(function(){
            console.log("timedout");
    
    
                $scope.bsTableControl = {
                options: {
                    data: makeRandomRows({ workspace: "test"}),
                    rowStyle: function (row, index) {
                        return { classes: 'none' };
                    },
                    cache: false,
                    height: 400,
                    striped: true,
                    pagination: true,
                    pageSize: 10,
                    pageList: [5, 10, 25, 50, 100, 200],
                    search: true,
                    showColumns: true,
                    showRefresh: false,
                    minimumCountColumns: 2,
                    clickToSelect: false,
                    showToggle: true,
                    maintainSelected: true,
                    columns: [{
                        field: 'state',
                        checkbox: true
                    }, {
                        field: 'index',
                        title: '#',
                        align: 'right',
                        valign: 'bottom',
                        sortable: true
                    }, {
                        field: 'id',
                        title: 'Item ID',
                        align: 'center',
                        valign: 'bottom',
                        sortable: true
                    }, {
                        field: 'name',
                        title: 'Item Name',
                        align: 'center',
                        valign: 'middle',
                        sortable: true
                    }, {
                        field: 'flag',
                        title: 'Flag',
                        align: 'center',
                        valign: 'middle'
                    }]
                }
            };
    
    
        }, 2000);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-02-15
      • 2020-03-26
      • 2018-01-27
      • 2016-08-21
      • 1970-01-01
      • 2012-06-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多