0

テーブル ヘッダーの並べ替えに角度ディレクティブを使用しています。しかし、HTML が分離されたディレクティブ スコープ内の変数に到達できないようで、何が間違っているのかわかりません。だから、あなたの一人が私を助けてくれることを願っています。

myApp.js

var koekoek = angular.module('koekoek', [ 'ui.bootstrap', 'ngRoute', 'sortTableHead']);

sortTableHead.js (固定テーブル ヘッダー ディレクティブ)

 (function(ng) {
'use strict';
var module = ng.module('sortTableHead', []);

module.directive('sortTableHead', [

    function() {
        return {
            restrict: 'A',
            transclude: true,
            replace: true,
            template: '<th class="selectable" data-ng-click="onClick()" >' +
                '<span ng-transclude class="pull-left"></span>' +
                '<i class="fa fa-sort pull-right" data-ng-class="{\'fa-sort-desc\' : order === by && !reverse,  \'fa-sort-asc\' : order === by && reverse, \'fa-sort\': !order === by}"></i>' +
                '</th>',
            scope: {
                order: '=',
                by: '=',
                reverse: '='
            },
            link: function(scope) {
                scope.onClick = function() {
                    if (scope.order === scope.by) {
                        scope.reverse = !scope.reverse;
                    } else {
                        scope.by = scope.order;
                        scope.reverse = false;
                    }
                }
            }
        }
    }
]);
})(angular);

View.html

<table id="dataTable" class="table table-striped table-hover">
    <thead>
        <tr>
            <th ng-repeat="(key, value) in data[0]" repeat-done="fixedTableHeaders()" sort-table-head by="order" reverse="reverse" order="'ipv4'">
                {{ key }}
            </th>
        </tr>
    </thead>
    <tbody>
        <tr ng-repeat="row in data  | orderBy:order:reverse | filter:searchText" ng-click="rowClickHandler(row)">
            <td ng-repeat="(varName, value) in row">
                {{ value }}
            </td>
        </tr>
</table>

コントローラ:

koekoek.controller('serversOverviewController', function($scope, $http, $location) {

$scope.rowClickHandler = function(rowData) {
    var selectedRowIp = rowData.ipv4;
    $location.path('/overview/' + selectedRowIp);
};

$http.get('server/serverList').success(function(data) {
    $scope.data = data;
});

$scope.fixedTableHeaders = function(){
    var $table = $("#dataTable");
    $table.floatThead({
        useAbsolutePositioning: true
    });
    $table.floatThead('reflow');
};

});

注文は今のところハードコードされています。

4

0 に答える 0