Jump to content

Recommended Posts

Posted

Is there something like that available in PW ? I need to filter something in a repeater by its last value.

Something like that: 

repeater.last.field

repeater.first.field

  • Like 1
Posted

The repeater is basically a PageArray. So you can use the normal Page/WireArray methods.

$myRepeater->first();

$myRepeater->last();

Look at the Cheatsheet under Page/WireArray. Hope this helps.

Sorry read it to fast.

But it's a PageArray and regarding to the documentation this might work:

$myRepeater->last()->find("myRepeater.fieldname != '' ").

Hopefully someone else can help.

Posted

After a bit of testing it seems that it takes into account all the values in the repeater (which is ok for my use). But I'd still like to know if it's possible to use selectors that way.

Posted

Don't understand the question exactly, but here are some nice docs: http://processwire.com/api/fieldtypes/repeaters/

Also repeater pages have a special template called "repeater_yourField". So theoretically you could also get repeater pages the following way:

// Get last item sorted by created DESC
$item = $pages->find("template=repeater_yourField,sort=-created,limit=1"); 

// Get first item sorted by created with an additional condition 
$item = $pages->find("template=repeater_yourField,sort=created,field|field2%=blub,limit=1"); 
  • Like 3
  • 3 years later...
Posted

would love that too, could use it on a table field to know while searching if the first/last entry matches

Posted
3 hours ago, Can said:

would love that too, could use it on a table field to know while searching if the first/last entry matches

It requires a couple of steps, but so long as your pages selector doesn't return a huge number of results this should be fairly low impact:

$value = 'Foo';
$all_matches = $pages->find("my_table.my_field=$value");
$first_row_matches = $pages->newPageArray();
foreach($all_matches as $match) {
    if($match->my_table->first()->my_field == $value) $first_row_matches->add($match);
}

 

  • Like 1
Posted

interesting approach thanks for sharing :-)

think the first subselector could be a nice addition to simplify things ;-)

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
×
×
  • Create New...