Smart-table : Disable column sorting

1.4k Views Asked by At

Below static example has sort on first name, but disabled sort on email column:

<tr>
    <th st-sort="firstName">first name</th>
    <th>email</th>
</tr>

But, my columns are dynamic. So I am creating dynamic column headers in an ng-repeat. Wether columns should be sortable or not is decided by an isSortable flag.

     <tr>
        <th st-sort="column.isSortable" ng-repeat="column in columns">{{column.columnName}}</th>
    </tr>

How do I make only the colums with isSortable set as true sortable?

1

There are 1 best solutions below

1
On

I suggest you set your st-sort on an inner element

   <tr>
    <th ng-repeat="column in columns"><span st-sort="column.sortProperty" ng-if="column.isSortable">{{column.columnName}}</span><span ng-if="!column.isSortable">{{column.columnName}}</span></th></tr>

and if you don't want to repeat yourself, you can embed this logic within a directive