Ajax Load more filterBy mehod

Hi all, I’ve followed Kirby load more recipe in order to get a custom list of events, and it works pretty good.

I have a single template to managed all the Events’ children, and once an event is created the user can select the typology between 2 values (option “A” / option “B”).

On the “Events” page I show all the children’s typologies, whereas on the additional page I need to show only the children with “option B” selected.

But I have two problems:
1 - All the events are created on a different page, so the query to load more doesn’t work:

   `${window.location.href}.json/page:${page}`

2- The method filterBy doesn’t work anymore once I fetch the other results:
(but It does for the first results, obviously in the JS I’m fetching all the children.)

  $events_page = $site->children()->findby('template', 'events'); 
  $list = $events_page->children()->listed()->filterBy('tipology', 'fest');

Are there any clever solutions? maybe without duplicating the content?

It might be best to use a route that returns the events page, but with an additional parameter to filter by.

I found an easiest solution due to a wrong configuration of my code.
I missed out to change the pagination() and return the page filterBy on my controllers.

Now it works as expected.
Thanks

Hi Samuele, are you able to share your solution? Thanks :slight_smile:

@nh_nh of course,
Basically, you have to follow the recipe.

In my case, you only need to change the controller “{template}.json.php” of the new pages as follow:

1- define page:

  $events_page = $site->children()->findby('template', 'events'); 

2- create a list:

  $list   =
    $events_page->children()->listed()->filterBy('tipology', 'fest')->paginate(20);
  $pagination = $list->pagination();
  $more       = $pagination->hasNextPage();

3- change return:

  return [
    'events' => $list,
  ];

That is a draft but works as aspected :slight_smile: