Jump to content

Sorting repeater


Frank Vèssia
 Share

Recommended Posts

You may also be able to setup an automatic sort by editing the repeater's template file and setting it under the 'Family' tab. Note that the repeater templates aren't visible in your templates list at first so you'll need to check the box to "show system templates" in the filter menu.

  • Like 3
Link to comment
Share on other sites

  • 1 year later...

Repeaters actually do have template files. In Setup > Templates > Filters, check the box to show system templates. However, this isn't going to help with sorting, as you'd need to define that on the parent. You could locate where your repeaters are stored in Admin > Repeaters and set the sort there, but you'd have to do it individually for each page. Ultimately, we need to just make this a configuration option with FieldtypeRepeater. 

Link to comment
Share on other sites

  • 2 years later...

Hey, sorry to resurrect this thread, but I think my question is closely related and if possible a better solution.

I am trying to sort my repeater before save using a hook, is this possible? Current code below doesn't work.

$pages->addHookAfter("saveReady", function($event){
	$page = $event->arguments[0];
	if ($page->template->name != "statistics") return;
	$page->stat_websitepageviews = $page->stat_websitepageviews->sort("date");
});
Link to comment
Share on other sites

  • 6 months later...
On 14/04/2016 at 1:21 AM, adamspruijt said:

I am trying to sort my repeater before save using a hook, is this possible?

Just looked at this issue recently. This seems to do the job:

$this->addHookAfter('FieldtypeRepeater::wakeupValue', function($event) {
    $field = $event->arguments('field');
    // Only for a particular repeater field
    // Could also use page argument for other tests
    if($field->name !== 'my_repeater') return;
    $pa = $event->return;
    $pa->sort("-created"); // or whatever sort you want
    $event->return = $pa;
});

 

  • Like 5
  • Thanks 1
Link to comment
Share on other sites

  • 1 year later...
2 hours ago, Tom. said:

I tried going to where you said however nothing about sorting shows up in Family. 

I think Ryan is talking about setting the sort on the parent page of the repeater page, not for a template.

On 23/09/2013 at 12:32 AM, ryan said:

However, this isn't going to help with sorting, as you'd need to define that on the parent. You could locate where your repeaters are stored in Admin > Repeaters and set the sort there, but you'd have to do it individually for each page.

So you locate the parent page under Admin > Repeaters and set a sort on the Children tab. But... this doesn't work because when setting an automatic sort like this it doesn't actually change the "sort" value of the pages in the database, which is what a repeater field uses to determine the sorting within the inputfield.

A related post that might be useful:

 

  • Like 1
Link to comment
Share on other sites

  • 1 year later...
On 11/10/2017 at 5:15 PM, Tom. said:

@ryanI can't seem to find any way to sort repeaters in the backend. Do you have any news on this? I tried going to where you said however nothing about sorting shows up in Family.  

Still no luck with sorting repeater items in the backend? I see the items nicely follow the sort settings in pagetree, but the order within the inputfield always stays the same.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...