Unlock seamless workflows and faster delivery with our latest releases ā€“ get the details

Using GROQ queries in Structure Builder for custom ordering

11 replies
Last updated: Aug 23, 2022
If I am using the Structure Builder, I see that there are filters, but it is quite explicit that I cannot feed it queries.
I wanted to take second pane child documents of my first pane's schema type, and apply a very particular order to them, but custom orderings depend on a string, which I don't have (I am doing some basic math to a nested value inside the color picker).

I thought about making a custom input that tried grabbing that and returning a string out of that to feed into the orderings object, but I'd much rather use a GROQ query ( with an
order qualifier at the end ) because that more or less returns the list I am after.
Is this possible? I get a bit faceblind with the terminology like list, list item, listtype, listtypeitem, etc. and while
user B
posted a useful example to pick a child at random, it's just the one item and my attempts to come up with a map -- even though the console logs the full list properly -- don't work. I can try to reproduce the explosion if someone needs exact errors but I'm not even sure if it's possible.
Aug 22, 2022, 10:06 PM
A
child()
can actually take a function. Even better, it can take an async function, which will allow you to use a GROQ query to get the documents you want! There's an example of this here . You can just tweak the query and use it! Make sure you install rxjs so that your lists will automatically include any new documents you create.
Aug 22, 2022, 10:22 PM
Wow,
user M
that was lightning fast! Thanks! I'll give it a shot.
Aug 22, 2022, 11:37 PM
Huzzah, a finished product: https://somup.com/c3j0VxUeIC
Aug 23, 2022, 1:33 AM
You really can do anything in :sanity: anity, it seems. In Star Trek : The Next Generation there was an episode that (spoilers) had them discover one base humanoid race that everyone supposedly came from, kind of as a way to explain why every new life form they discovered wasn't really much different and always somehow managed to resemble people covered in makeup and foam šŸ˜ƒ
Sanity is like we're doing things backwards. This is such a raw, pure form of content creation that you'd think it was first and everyone else was a derivative that came after, just because it seems so direct and capable in comparison to, well,
literally everything else.
Instead it is here, fresh and modern like a vanguard, saving us from the perils of the past like an S-shaped angel!
šŸ˜›
Aug 23, 2022, 1:39 AM
Ahh, I love getting to see inside the Studios people build, so thank you for sharing! We need a Sanity :sanity: with angel wings on it!
Aug 23, 2022, 4:30 PM
it's beautiful
Aug 23, 2022, 4:50 PM
:sanity-wings:
Aug 23, 2022, 4:52 PM
Now that is beautiful!
Aug 23, 2022, 4:57 PM
I give it 5 out of 5 :knut: :knut: :knut: :knut: :knut: s
Aug 23, 2022, 4:57 PM
petitioning to make this an official standard of rating stuff in sanity!
Aug 23, 2022, 5:56 PM
"My god! It's a 5 on the :knut: scale!"
Aug 23, 2022, 5:58 PM

Sanityā€“ build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?