智能表:ng-repeat

时间:2015-11-10 10:56:40

标签: angularjs smart-table

我正在使用Angular Smart Table,它非常好,但我遇到了与排序有关的问题:

让我们假设我有一些列定义,对于每一列我都有信息是否可以按此列排序:

$scope.columns = [
    {
        id: "id",
        sortable: true
    },
    {
        id: "type",
        sortable: false,
    }
];

在我的html文件中,我想用ng-repeat声明表头,以避免在列定义中的某些内容发生更改时进行愚蠢的重构。 Somethig喜欢这样:

<table class="table" st-table="records">
 <thead>
  <tr>
   <th ng-repeat="column in columns"> {{ column.title }} </th>
  </tr>
 </thead>
 ....
</table>

所以我的问题是:如何设置属性&#34; st-sort&#34;仅适用于那些 column.sortable 为真的列? 我尝试使用自定义指令,根据 column.sortable 添加此属性并实际添加它,但st-sort在这种情况下不起作用(可能是因为此指令编译在表编译后发生,我不知道......)

1 个答案:

答案 0 :(得分:3)

这应该有效:

<table st-table="records">
  <thead>
    <tr>
      <th ng-repeat="column in columns" st-sort="{{(column.sortable) ? column.id : null}}">
        {{column.id}}
      </th>
    </tr>
  </thead>
  ...   
</table>
相关问题