智能表" st-sort"不工作

时间:2015-03-30 10:03:58

标签: angularjs smart-table

我使用角度v1.3.15。我通过点击api并将其通过范围传递到智能表来获取数据,如此

enter image description here

以下是' scope.rowCollection'的数据格式。如在控制台上看到的那样

enter image description here

数据填充正常但是当我尝试单击表标题并使用st-sort方法对其进行排序时,表值显然为空,而不是对列进行排序。这是我的html代码段的视图

enter image description here

你能告诉我我做错了什么吗?我使用自己的数据收集集(非硬编码)的那一刻,整个表格值变得混乱。 我感觉它与我在角端使用的变量名称有关。 非常感谢任何帮助....谢谢

3 个答案:

答案 0 :(得分:29)

点评你的评论Nikhil。像这样使用 st-safe-src

<强> HTML

<table st-table="displayedCollection" st-safe-src="rowCollection">
      <thead>
        <tr>
          <th st-sort="firstName">First Name</th>
          <th st-sort="lastName">Last Name</th>
        </tr>
      </thead>
      <tbody>
        <tr ng-repeat="row in displayedCollection">
          <td>{{row.firstName}}</td>
          <td>{{row.lastName}}</td>
        </tr>
      </tbody>
</table>

<强> JS

app.controller('Ctrl', function($scope, service) {
    $scope.displayedCollection = [];

    service.all.then(function(list) {
        $scope.rowCollection = list;
        $scope.displayedCollection = list;
    });
});

那就是它。

答案 1 :(得分:4)

如果要异步引入数据(从远程数据库,restful端点,ajax调用等),则必须使用stSafeSrc属性。您必须为基本集合和安全集合使用单独的集合,否则最终可能会出现无限循环。

因为我从宁静的服务中获取数据 st-table =“displayedCollection”st-safe-src =“rowCollection” 解决我的问题

答案 2 :(得分:1)

我认为它正在尝试按照编码方式对row.name进行排序。请尝试以下操作以查看它是否有效:

     st-sort="employee.name"
相关问题