Sorting FileList by custom attribute key

I set up the attribute key as searchable. I figured I could use the sortBySearchColumn() method and give it the attribute key handle but turns out it needs a Column object. I don’t know what that is. So how do I sort by a custom attribute key? Also, where is this documented? You would think it would be documented here (Searching and Sorting with the FileList Object) as all public methods of the FileList class should be, but it is not for some reason that makes absolutely no sense to me.

Hello again @sparkymeister
A dev will follow up on your search questions.

I’ve added your suggestion to update the searching and sorting doc. Your suggestions are really useful to prioritize what needs updating. Cheers

@sparkymeister Concrete\Core\File\FileList | ConcreteCMS API


This does not answer anything.

Sorry, clicking the sort by method scrolled me down a little too far and I didn’t notice. But sortBySearchColumn() isn’t useful either. It does not explain how to use it or really even what it is supposed to do.

API documentation like what you are linking to should not be considered a primary source of documentation. It’s really only good for people who already know what they’re doing and just need a refresher on methods available or what a certain methods argument list is. In fact, modern IDEs make these api docs unnecessary as they provide the exact same info on autocomplete.

Every class you intend developers to use should be documented as well as every public method on those classes.

I disagree here about the usefulness of the API guide. I find it super useful.

Also when looking in the concrete folder for various blocks or code in a project I find loads of it has comments explaining what is possible.

Although yes the documentation does need some expanding I think the core team have done some great work.

Yeah, actually I agree. “Sorting” part is a little lacking in “File List” docs.

// handle of file attribute: custom_attribute
$list->sortBy('ak_custom_attribute', 'desc'); // file attribute handle should be prefixed with "ak_" here
$list->sortByCustomAttribute('asc'); // alternative magic function for sorting

sortBySearchColumn() is another more “object-oriented” option, but I think it could be a little overkill for single/simple query (but, indeed, it should be included in docs).

You shouldn’t have to scour the source code for gems. They should be on full display in the docs so you don’t have to jump into that rabbit hole. Some people are trying to get things done. Time is all we have.

Sortby() isn’t documented. Magic methods especially need to be documented because how do you know they exist unless you’re the magician who created them?

1 Like

I think it’s just an omission.

All my examples + custom query builder example (another option how to change sorting) are in Page List documentation.

Page List/File List have very similar API, so many methods are exactly the same.