Adaptive-card sortby on datetime property

15 Views Asked by At

I'm building an adaptive card from some json using adaptive expressions to select data from the json. I cannot seem to figure out how to do sortby datetime

The expression "$data": "${sortByDescending(where($root.result, y => y.jobTitle == $data), deadline)}" Does not sort properly when specifying "deadline" as the property to sort on, my guess is because it tries to sort alphabetically. Sorting on Title this way works fine. I tried replacing "deadline" with ticks('deadline') in the hope it would sort by int, but that broke the designer.

Is there a way to sort by datetime?

{
    "type": "AdaptiveCard",
    "body": [
        {
            "type": "TextBlock",
            "size": "Large",
            "weight": "Bolder",
            "text": "Jobs"
        },
        {
            "type": "Container",
            "$data": "${unique(select(result, x => x.jobTitle))}",
            "items": [
                {
                    "type": "TextBlock",
                    "text": "${$data}",
                    "weight": "Bolder",
                    "size": "Medium",
                    "wrap": true
                },
                {
                    "type": "ColumnSet",
                    "columns": [
                        {
                            "type": "Column",
                            "items": [
                                {
                                    "type": "TextBlock",
                                    "text": "${title}",
                                    "style": "default",
                                    "weight": "Bolder",
                                    "color": "Dark"
                                },
                                {
                                    "type": "TextBlock",
                                    "text": "${formatDateTime(deadline, 'yyyy-MM-dd HH:mm' )}",
                                    "$when": "${deadline != null}",
                                    "isSubtle": true
                                }
                            ],
                            "width": "auto"
                        }
                    ],
                    "$data": "${sortByDescending(where($root.result, y => y.jobTitle == $data), deadline)}"
                }
            ]
        }
    ],
    "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
    "version": "1.6"
}

source data:

{
   "result":[
      {
         "title":"some text 3",
         "jobTitle":"Digger",
"deadline": "2024-12-12T21:59:00Z"

      },
      {
         "title":"some text",
         "jobTitle":"Filler",
"deadline": "2024-12-21T21:59:00Z"
      },
      {
         "description":"some text2",
         "jobTitle":"Digger" ,
"deadline": null       
      }
   ]
}

0

There are 0 best solutions below