生成的ng表排序不起作用

时间:2015-01-22 17:04:07

标签: angularjs ngtable

我想展示这样的东西:

enter image description here

通过单击列标题(th),对我的表进行排序。 但是,我没有设法将ng-table组件与我的数据结构一起使用。表格显示正确,但排序无效。

Not working demo

HTML

<table ng-table="tableParams" class="table">
    <tr class="keyword-info">
        <th></th>
        <th ng-repeat="keyword in AppKeywords[0].keywordDensity">{{keyword.keyword}}</th>
    </tr>
    <tr class="keyword-info" ng-repeat="app in AppKeywords">
        <td><span class="bold">{{app.name}}</span><br>{{app.totalKeywordDensity}}% ({{app.totalKeywordCount}})</td>
        <td sortable="'stats.density'" ng-repeat="stats in app.keywordDensity">{{stats.density}}% ({{stats.number}})</td>
    </tr>
</table>

控制器

$scope.tableParams = new ngTableParams({
    page: 1,            // show first page
    count: 10          // count per page
}, {
    total: $scope.AppKeywords.length, // length of data
    getData: function($defer, params) {

        var orderedData = params.sorting() ?
            $filter('orderBy')($scope.AppKeywords, params.orderBy()) :
            $scope.AppKeywords;

        $scope.AppKeywords = $filter('orderBy')($scope.AppKeywords, params.orderBy());
        $defer.resolve($scope.AppKeywords);
    }
});

AppKeywords:

Console.log($scope.AppKeyword)

1 个答案:

答案 0 :(得分:0)

我不确定您的表格是否结构化但通常ng-table sortable需要&#39;&#39;,

所以试试

<td sortable="'stats.density'" ng-repeat="stats in app.keywordDensity">{{stats.density}}% ({{stats.number}})</td>