Forum

Thread tagged as: Question

Sorting entries by two values.

So I have a tabular set of data which has increasing sixes for A, B, C measurements. I want to be able to sort this data first by A size then by B Size. Anyone know if this is possible with Perch?

I know I can sort by A only. However, some of the values might be the same for A, then it should sort these by the B value. For example.

A:12 B:6 C:2
A:12 B:8 C:15
A:12 B:10 C:2
A:12 B:30 C:14

If I sort by A then the other orders sometimes become jumbled….

Terry Upton

Terry Upton 0 points

  • 4 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

You'd need to make a composite field and then sort by that.

https://docs.grabaperch.com/templates/field-types/composite/

Thanks Drew. I have tried this before and having another crack now. But as these values are essentially numeric, I am not sure the composite field helps, as it just combines the string values and doesn't add them together to create a sortable numeric value (if this makes sense). Any ideas?

I can send you a link to the site if it helps to visualise what I am trying.

Drew McLellan

Drew McLellan 2638 points
Perch Support

No unless you're able to pad them, no.

Nope, afraid padding doesn't seem to work. Is there anyway to remove the spaces from the composite field? I have tried replace.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Nope. The only way would be with a custom field type.

Ok thanks Drew. I will look into this and see if I can create a custom field type or some more complex multi-array sorting function on the front-end. One thing that would get around this quite easily is that the back-end allows you to sort items manually, so the client has done this and has them in the right order. What would be a nice feature would be to add an item at a specific point in the list. Rather than just top or bottom. Perhaps an item item next to the delete button that adds the item to the top/bottom depending on the settings.

See my example on this site, there are over 234 entries, when they want to add more and quickly it is a pain to have to manually drag each one after adding to the right place each time. Instead an insert at the right place I feel would be a valuable feature. Any thoughts?

See mockup and existing screenshot.
https://cl.ly/3e1w1d3k3g0W
https://cl.ly/2o2g350v2911

Drew McLellan

Drew McLellan 2638 points
Perch Support

That's a lot of items in a region - you might want to look at importing it to a collection instead.

Ok I will give this some thought. I have several products setup this way; If you take a look at the website (https://www.grommets.co.uk) it might give you a better idea. All of these pages use the same template but with different region templates (based on the table values (a,b,c,d,e etc). So I would need to create a collection for each product. So migrating might be sensible but would be a fair amount of work.

However, would a collection help resolve my problem above?

Drew McLellan

Drew McLellan 2638 points
Perch Support

No, it won't help with that. We'll keep it in mind, but we'd need to see high demand before adding further complexity.