Frank Vèssia Posted August 20, 2012 Share Posted August 20, 2012 Can I sort elements of a repeater ? Sort for ID or custom field? Link to comment Share on other sites More sharing options...
Frank Vèssia Posted August 20, 2012 Author Share Posted August 20, 2012 Ok found... $page>repeatername->sort("id"); 1 Link to comment Share on other sites More sharing options...
ryan Posted August 20, 2012 Share Posted August 20, 2012 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. 3 Link to comment Share on other sites More sharing options...
globi Posted September 19, 2013 Share Posted September 19, 2013 Hallo! I just tried to sort the repeater by setting the sort under "Family" tab, but since my repeater doesn't have a template-file, there's no sorting option in the "Family" tab?What can I do about it? Please advise. Thanks!! Link to comment Share on other sites More sharing options...
ryan Posted September 22, 2013 Share Posted September 22, 2013 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 More sharing options...
adamspruijt Posted April 13, 2016 Share Posted April 13, 2016 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 More sharing options...
Robin S Posted November 2, 2016 Share Posted November 2, 2016 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; }); 5 1 Link to comment Share on other sites More sharing options...
Tom. Posted November 10, 2017 Share Posted November 10, 2017 @ryan I 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. 1 Link to comment Share on other sites More sharing options...
Robin S Posted November 10, 2017 Share Posted November 10, 2017 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: 1 Link to comment Share on other sites More sharing options...
Autofahrn Posted March 4, 2019 Share Posted March 4, 2019 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now