Adding multiple sorts to a repeater

repeater-widget

#1

I am trying to prototype up an activity log, where the user enters how many miles they completed and the date, and a new row gets added to their activity log. I’ve successfully made it this far, and have made it sort in descending order by date so that the most recent activities are at the top.

What I’m struggling with is adding a “day” column indicating what day the activity took place, starting with 1. Ideally the day would correspond with the date, so if you don’t log an activity on day 8 for example, the numbers would jump from 7 to 9. I imagine that will be complicated, so I’d be happy with just getting that “day” column to increase by 1 each time you add an activity, and to be in descending order like the “date” column." Users should be able to add activities in any order and they’ll be sorted appropriately in the log.

Can I use the item index for this, or do I need a custom sort column like in this solution? Add new row at top of repeater

I’m fairly new to manipulating repeater data, so any help would be greatly appreciated.


#2

Hi!

There are many date manipulation functions in Axure, so this problem is solvable.

In Javascript (which the Axure functions are based on), dates are stored as the number of milliseconds that have transpired since an arbitrary date in the 70s. So if you were to store dates in those milliseconds, and upon displaying them (in On Item Loaded) convert them back to readable dates, that would solve a bunch of issues. For instance, getting the day of the week would be trivial. Plus, sorting would just naturally work out, because the more recent the date, the larger the milliseconds.

Let me play around with an example and get back to you…


#3

I’m back. Here is a solution.

Upon entering a date (in practically any valid format: e.g. July 4, 2020 works, as does 7/4/2020), the repeater stores it using the valueOf() function, which puts milliseconds as discussed above into the repeater column.

On Item Loaded, the date is converted back to various formats using date functions. (The “+ 0” you see in the formulas forces conversion into an integer, which the date functions expect.)

There is a sort on the repeater which puts the most recent dates first.

I recommend this Medium article on the repeater, because not only does it describe in detail how Item Loaded actually works, it happens to go into expressions, as well as the various date functions.

But I’m hoping the example is self explanatory.

Preview

file: store date natively in repeater.rp (50.6 KB)


#4

Thank you so much for taking the time to look into this! I’ll check it out today and let you know if I have any other questions.


#5

I was able to get the “day” column working properly by using the solution outlined here to sort by item.index in descending order Repeater - problem with counting (Sort + Delete Rows)

Everything seems to be working as I’d hoped it would!