Trying to sort "files" section in panel by date added

I’m trying to sort files by date added. Using sortBy: date desc doesn’t work. The closest is sortBy: modified desc but the downside is if you click a file and edit a field it will bump to the top.

This is the blueprint:

media:
  sections:
    info:
      text: Media files that are added to this library can be accessed from any page.
      type: info
    files:
      headline: Files
      layout: cards
      sortBy: modified desc
      type: files

Do these files actually have a date field to sort by?

Nope :grimacing:

I just added a date field and as you know my hook sets the field values when uploading.

Date field I’ve added:

date:
  default: now
  disabled: true
  label: Uploaded on
  time: true
  translate: false
  type: date

In the hook:

$mediaImage = [
  'Alt'     => '',
  'Caption' => '',
  'date'    => date('Y-m-j G:i'),
];

This works. Is date('Y-m-j G:i') the way the date time field sets values by default?

1 Like

No, the default is Y-m-d H:i, i.e. with leading zeros.

2 Likes

Thanks!