Home > Forum > General > How to Set order of Attachments Category?

How to Set order of Attachments Category?
0

How to Set order of Attachments Category?

I Have category list::
ID=1 Name starts from "P"
ID=2 Name starts from "U"
ID=3 Name starts from "A"

I would like to sort category by "ID of Category" not by Category Name Letter / number ..

work around will be probably ad 1. 2. 3. to order names ... but ... there is other way ?

MVP

Hi Paweł,
As far as i know, there is no built in way to change the sorting.
I'd go with prefixing categories, as you've already have described.

You could also go with a javascript solution, something like this:

const list = document.querySelector('#attachments > * ul'); // this will get unordered list of attachments

// this function is responsible for sorting - you could tweak it, data-drop contains attachment category in format id#name.
let compare = (a, b) => {
let aAttr = a.getAttribute('data-drop');
let bAttr = b.getAttribute('data-drop');

if (aAttr < bAttr) return -1;
return 1;
}

// Here we change list childrens (so attachments) to array, sort it, and based on that reordering them in the ui using list.append.
[...list.children]
.sort(compare)
.forEach(node => list.appendChild(node));

Did you know that with WEBCON you can automate virtually any process? Even baking cookies 🍪
 
Speaking of cookies: we use the ones that are essential for our website to function properly, as well as additional ones that help us customize our content to your preferences. If you don’t mind cookies, click Accept. If you want to learn more, explore settings.
Settings