Using smart-table sorting by dynamic map value

220 Views Asked by At

I have a table to show records. One of it's columns contains select, to choose the version of the record. The second one is the map of dates, where keys are the versions. This looks like this:

    <td><select ng-model="record.currentVersion"> ...</td>
    <td>{{record.dates[record.currentVersion]}}

I'd like to add sorting by the second column's value, but I'm not sure how to address object's own property in st-sort. Something like st-sort="dates[currentVersion]" doesn't work. Is this possible to do?

1

There are 1 best solutions below

0
On BEST ANSWER

Define a new function:

$scope.getDate = function(record) {
  return record.dates[record.currentVersion];
};

Use st-sort:

<th st-sort="getDate">Date</th>

Demo: http://plnkr.co/edit/l6poIsZ2YHUyeFf4TdET?p=preview