Jump to content

Change order of Wire/PageArray based on a pageField


a-ok
 Share

Recommended Posts

Is it possible to sort a Wire/PageArray (I'm using the RepeaterMatrix) by a field's value? The order is defined by the order in the CMS but if I wanted to change that order, on the front-end, to follow a pageField selection is this possible?

Each row has a pageField that allows the client to select a number of categories that defines that row's content. If the client selects 'Digital' for a row then is there a way, on the front end, to put all the rows with that category first (thus breaking the order)? I would then use a get request (?f=digital) to define when the order should change, but I'm just wondering if the sorting order change is possible.

I could probably loop through the rows and remove/append but wondered if this was possible within a selector?

Link to comment
Share on other sites

I ended up with...

$modules = $page->modulesA;

if ($input->get('f')) {
    $moduleFilter = $input->get('f');
    $modulesWithFilter = $modules->find("projectsCategories.name={$moduleFilter}");
    $modulesWithoutFilter = $modules->removeItems($modulesWithFilter);
    $modules = $modulesWithFilter->add($modulesWithoutFilter);
}

 

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...