Jump to content

Recommended Posts

Posted

I would like to order the display of a repeater in the backend on the basis of a field in it; my repeater is called dates_events and contains a title field and a date_event field. How can I display the values in admin by sorting by dates_events?
I have tried with a hook but this does not work

the date_event is a date/time field

$wire->addHookAfter('InputfieldRepeater::render', function(HookEvent $event) {
    $inputfield = $event->object;
    if ($inputfield->name === 'date_events') {
        $inputfield->value = $inputfield->value->sort('data_event');
    }
});

Thank you in advance

Posted

Hi,

i use thie on musicians and bands websites and it works quite well (in the ready.php file)

$this->addHookAfter('FieldtypeRepeater::wakeupValue', function($event) {
    $field = $event->arguments('field');
    if($field->name !== 'date_events') return;
    $pa = $event->return;
    $pa->sort("date_event");
    $event->return = $pa;
});

you could of course easily choose to order by reverse chronological order using $pa->sort("-date_event");

hope it will be a little useful 🙂

have a nice day

  • Like 2
Posted

Thank you this work fine

1 hour ago, virtualgadjo said:

Hi,

i use thie on musicians and bands websites and it works quite well (in the ready.php file)

$this->addHookAfter('FieldtypeRepeater::wakeupValue', function($event) {
    $field = $event->arguments('field');
    if($field->name !== 'date_events') return;
    $pa = $event->return;
    $pa->sort("date_event");
    $event->return = $pa;
});

you could of course easily choose to order by reverse chronological order using $pa->sort("-date_event");

hope it will be a little useful 🙂

have a nice day

 

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
  • Recently Browsing   0 members

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