Sort table column by date

Josh Willing:
My onFormRequest hook sets this in my model:

"recentPushes": [
        "action": "PUSH_INVOICES",
        "timestamp": "12/22/2023 1:20:35 AM"
        "action": "PUSH_PAYMENTS",
        "timestamp": "12/23/2023 2:30:45 AM"

I’m displaying that in a table2 like pictured. The timestamp column is sorted descending but the order is wrong.

Is there a way to preprocess the recentPushes array to convert the timestamps to dates (or treat them as dates) that sort properly in the table?


Andrew Dam:
You can reference this forum post for an implementation of this.

The associated example can be found here as well.

Josh Willing:
I’ll take a look thx!

Josh Willing:
YES perfect!

EDIT: posting my actual code for posterity if anyone else has the same issue. In the options of the table2 object:

"customSorting": {
    "timestamp_function": "const ascending = arguments[0]; return function(a,b){if (ascending) return new Date(a.timestamp) >= new Date(b) ? 1 : -1;}"

Andrew Dam:
Awesome, glad we were able to assist!