0

私はAngularJsを初めて使用し、スマートテーブルプラグインをディレクティブ内に「ラップ」しようとしています。行を取得できますが、ページネーションが表示されません

現在、これは私がやったことです。

    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>

このコードは単なるテストです。データはサービスを使用して渡され、テンプレートは動的になります。助けが必要です :-)

ありがとう

4

2 に答える 2

1

先日smart-tableをディレクティブで使っていたら、ページネーションが表示されませんでした。ディレクティブとは何の関係もないことが判明し、GitHub から最新バージョンの smart-table にプル/更新しただけで、すべて機能しました。私は何が変わったのかを調べ始めましたが、横道にそれて、より生産的なものに移り、それが機能していることに満足しました. 正常に動作しているように見える私が持っているバージョンは、1.4.2 とタグ付けされています。

ただし、サービスからの動的データでは、st-safe-src 属性も確認する必要があると思います。私はこのAngular / smart-tableビジネス全体も初めてですが。

于 2014-10-29T08:50:31.497 に答える
0

ページネーションを表示するには、st-table 値と st-pagination 値を一致させる必要があると思います。

于 2015-02-01T05:58:26.087 に答える