Contentful logo

Contentful Community

Any workarounds for Sorting Media Assets?

Hello,

I am desperately looking for a workaround or a potential solution for sorting media assets. I currently have a field called “Images” that accepts multiple media assets. I use this to create a gallery for my website that normally has between 75 -150 images. What I can’t figure out is how to sort media assets. I tried naming the assets like so: example-1.jpg, example-2.jpg but the order they show up in is so sporadic and I have no idea what the order is based on.

Does anyone have a suggestion for how to sort media assets prior to inserting them into the field? The drag and drop sorting is okay when you have a few items but it is a terrible user experience if you are trying to drag and drop 150 randomly sorted items. I find it hard to believe I am the only person that wants the ability to sort media assets. (see image attached)

Perhaps some type of query string exists when using the filter search to sort them as well?

Thanks,
Ryan

Hi @ryan2,

This is indeed a current limitation and we already opened a feature request for a sorting mechanism. In the meanwhile, it’d be possible to create an UI extension from scratch, but it might be a bit of an overkill for your use case.

Let me know if you have other questions :slight_smile:

2 Likes

@gabriel,

Thanks for the response back. I’m glad to see there is already a feature request open for this. Anything you can comment on regarding a timeline for that? Is that something likely to be addressed in the next few weeks, months, or years?

Creating my own UI extension does sound intense but I may look into that if you think it won’t be addressed in the future.

Thanks again,
Ryan

Hi @ryan2

You can use the media entry’s field Title to sort your assets on the application level - assuming you have named your media entries with a running number e.g.

  • Forest Gallery Photo 001
  • Forest Gallery Photo 002
  • etc.

I did something similar recently. Even though it was entry relations, the general principle should be the same. In Ruby it worked something like this (I’m paraphrasing from memory, so don’t quote me on that :grinning:).

labels = entry.fields[:labels].to_a.sort_by(&:name)

1 Like

@teemu.tammela1,

That’s a valid option and it did cross my mind to force the order via code. With that said I didn’t feel it was flexible enough and I’m kinda hoping (perhaps too optimistically) that sorting will be added soon.

@ryan2

Yeah, I see where you’re coming from. A word of advice tough;

The company I work for…you could say we’re quite hardcore users of Contentful and use it for large-scale projects. One thing we find ourselves constantly having a philosophical debate over, is to which extent should Contentful - or rather a function built into Contentful - control the presentation layer.

After some careful consideration, 9 times out 10 we realise that Contentful is the wrong place to do it, since it would end up littering our content models with all kinds of gimmicks, hacks and pseudo-content fields…which resembles a lot of traditional CMS’s like Drupal, that we fought long and hard to get rid of.

Usually the biggest reason Contentful turns out to be wrong tool for controlling presentation layer, is that various presentation scenarios (e.g. desktop and mobile) might need different presentation settings. In other words, whichever sorting etc. method you would apply in Contentful, it might not be the desired option for all use cases.

As a rule of thumb, everything that is not actual content that you add to your content models, is going to have a negative impact on your content’s life cycle.

Everything above might not apply to your situation per se, but never hurts to drop some knowledge, right? :slight_smile:

6 Likes

@teemu.tammela1,

That is very good advice. I agree 100%.

With that said I still think it would be in Contentful’s best interest to continuing improving the user experience for dealing with Media Assets. The addition of filtering shows they are headed in the right direction. Now if they can build on that foundation and add simple sorting I know it would be beneficial without going against the their core CMS Philosophy.

Thanks again for your input and advice!

1 Like

@teemu.tammela1 and @ryan,

Thank you so much for all the help and feedback - this is awesome :slight_smile:

That being the case, I already created a feature request for this and, with all of this great information, it will definitely help our team understand your use case in more detail.

It would be a great small improvement to be able to sort the entries on the media tab.

This is pretty basic:

  • We need sorting by Header fields
  • Be able to change number of results per page

When will this be live ?