2015-11-10 32 views
0

我採用了棱角分明的智能表,這是相當不錯的,但我面臨着與排序問題:智能表:在有條件的ST-sort屬性NG-重複

讓我們假設我有一些列的定義和每列我有信息,我是否可以通過此列或不進行排序:

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

在我的HTML文件,我想,當列定義的東西變爲申報與NG-重複表頭,以避免愚蠢的重構。 Somethig這樣的:

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

所以我的問題是:我怎樣才能設置屬性「ST-那種」只對那些列,爲此column.sortable是真的嗎? 我試圖使用自定義指令添加此屬性取決於column.sortable它實際上添加它,但ST排序在這種情況下不起作用(可能是因爲此指令編譯發生在表編譯後,我不知道...)

回答

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

謝謝你,我傻,忘了花括號! –