New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expose Laravel Loop Object To Column #4857
Expose Laravel Loop Object To Column #4857
Conversation
This PR Expose Laravel Loop Object To Column, We can use it like below Tables\Columns\TextColumn::make('sl')->getStateUsing(function ($loop){ return $loop->iteration; }),
|
Instead of |
You mean instead of loop object just pass an int that starts from 0? |
well at the moment you're passing in the column loop object and not the row loop object? i think? which is wrong right? |
Yes, if we pass the loop object, we will have some extra options like remaining, count, depth, last etc, which will help if we need those. But it's your call , i will update the PR if you think loop object is not a good fit. |
I agree now that the loop object is fine, but please test your code. I don't think it works, as you're passing in the column loop and not the row loop. For clarity we can name it |
Changed loop method to rowLoop. And fixed issue with loop object.
I've just refactored a bit, does it still work? |
Not Working With Stack & Split. |
{{ $layoutComponent->viewData(['recordKey' => $recordKey, 'rowLoop' => $rowLoop]) }} rowLoop has to be passed in viewData. |
Fixed Issue After Refactoring.
@Nuhel how about passing it into the object instead and then using |
May be i did not get you, can you elaborate please? |
I've made the changes, test again please |
Yes working. Should I update documentation? And I am thinking to add below function to CanFormatState Trait public function rowIndex(bool $fromZero = false): static
{
$this->getStateUsing(static function ($rowLoop) use($fromZero): ?string {
return $rowLoop->{ $fromZero? "index":"iteration"};
});
return $this;
} |
Sometime we need to show the Serial Number/Iteration Number in table. I could not find any way to do this with filament table. (May be there is a way, if so i will close this PR)
This PR Expose Laravel Loop Object To Columns,
We can use it like below
Also as it is laravel's foreach loop object, We can access every other property like
index, remaining, count etc.