0

I am using smart-table to display generic lists of data built up as an array of objects in code. I wish to be able to apply sorting on any of the columns, how do I pass the column name to sort on to the getter? At the moment I can only sort on a hard coded column.

{{item.displayName}}

{{item.displayName}}

1 Answers1

0

All you need yo do is match the st-sort with the corresponding name in the tables body, see example below. Clicking "Age" will then only sort the "Age" column.

<table st-table="example" class="table table-striped">
  <thead>
    <tr>
      <th></th>
      <th st-sort="name">Name</th>
      <th st-sort="age">Age</th>
    </tr>
  </thead>
  <tbody>
    <tr ng-repeat="example in examples">
      <td cs-select="row"></td>
      <td>{{example.name}}</td>
      <td>{{example.age}}</td>
    </tr>
  </tbody>
</table>
Pianoc
  • 763
  • 1
  • 11
  • 32