智能表:ng重复中的条件st排序属性



我使用的是Angular Smart Table,它非常好,但我面临着与排序相关的问题:

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

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

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

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

所以我的问题是:如何仅为column.sortable为true的列设置属性"st排序"?我试图使用自定义指令来添加这个属性,这取决于列。sortable,它实际上添加了它,但st排序在这种情况下不起作用(可能是因为这个指令编译发生在表编译之后,我不知道…)

这应该有效:

<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>

最新更新