Skip Navigation

[Resolved] How can I allow the user to sort Repeatable Field Group view output?

This support ticket is created 5 years ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 2 replies, has 2 voices.

Last updated by ericE-4 5 years ago.

Assisted by: Waqar.

Author
Posts
#1428267

I have a Repeatable Field Group ("Package") which contains a nested Repeatable Field Group ("Package Details"). I've created a view ("Pricing packages list") that outputs every Package Details record for every Package for the current post. I'm trying to sort the resulting list by one of the fields ("Number of Nights") by default, AND allow the user to control the sorting.

I have tried adding sorting controls to the "Pricing packages list" view, but when I do so, it stops any records from being output (I since reversed this change).

Is there any way to sort my output table of pricing packages?

Example: hidden link

#1431117

Hi Eric,

Thank you for contacting us and I'd be happy to assist.

Based on what you've shared here and in the previous ticket ( https://toolset.com/forums/topic/view-returns-zero-results-after-adding-sorting-control/ ), I understand that the challenge here is that the list's layout is dependant on two views (nested in each other) and sorting controls are needed for the custom fields which are attached to the child view's repeating field group and not to the parent one.

The way WordPress post query works, if a custom field key is used to order the results, it will only fetch those results, which have any custom field record with that key attached. Any posts, without any record with that custom field key, will be ignored.
( this is why you were seeing 0 results earlier, as Minesh explained )

A better alternative way to offer front-end sorting functionality, in this case, would be to stop using Toolset View's own sorting feature and use a third-party table sorter script, which doesn't involve, database queries.

You'll first reconstruct the list so that it uses a table structure, making sure that fields that you'd like to use for sorting have their own column (e.g. nights, fishing days, price, etc).

After that, you can include any of the following third-party scripts, to include front-end table sorting:

hidden link
hidden link

I hope this helps and please let me know if you need any further assistance around this.

regards,
Waqar

#1432513

Awesome, that makes perfect sense. Thanks for the insight and recommendation. It's too bad Toolset doesn't offer this functionality, but I can certainly use a front-end sorting script.