0

I'm looking for a way to implement a moving table-row to indicate my current time in a table with timestamps.

<table>
    <tr ng-repeat="timestamp in timestampArray">
        <td>{{timestamp}}</td>
    </tr>
</table>

Current table:

enter image description here

What i want to achieve:

enter image description here

The table-row with "NOW" should move automatically according to the current time.

Thanks for the help.

Xavier L.
  • 368
  • 1
  • 11

1 Answers1

1

you can compare your ng-repeat timestamp value to today's timestamp value and can handle this by using ng-if.

like

    <table>
        <tr ng-repeat="timestamp in timestampArray">
 <td>{{timestamp}}</td>
            <td ng-if="timestamp == todaytimestamp">Now</td>
        </tr>
    </table>
Hrishikesh Kale
  • 6,140
  • 4
  • 18
  • 27
  • Reading this question again, i'm not completely sure this is what the OP mean, because in the current table there there are 4 rows, and in the desired outhup there are suddenly 5 rows – Alon Eitan Feb 20 '18 at 13:09
  • so basically we could remove the not condition from the ng-if statement. so whenever the timestamp matches today's timestamp now will display. – Hrishikesh Kale Feb 20 '18 at 13:13
  • Perhaps.. If the OP could clarify this, then we'll know for sure. But your solution should work perfectly – Alon Eitan Feb 20 '18 at 13:14
  • yeah let's see. if not we can handle this other way around. – Hrishikesh Kale Feb 20 '18 at 13:15
  • basically I want a separator with all timestamp before the current time above it, and all timestamps after the current time under it. This separator should move according to the current time ofcourse – Xavier L. Feb 20 '18 at 13:16
  • why not using order by in ng-repeat! you can have a look here https://stackoverflow.com/questions/16261348/descending-order-by-date-filter-in-angularjs – Hrishikesh Kale Feb 20 '18 at 13:20
  • ordering this by timestamp it will automatically update the table and will also display the NOW in a proper place. – Hrishikesh Kale Feb 20 '18 at 13:21