Skip to content

Row iteration #2019

Answered by lrljoe
mhmmd-iqbal asked this question in Q&A
Oct 27, 2024 · 1 comments · 2 replies
Discussion options

You must be logged in to vote

So the simplest way to do this, assuming you want it to start at "1" not "0"

First you need to add an Alpine attribute to expose the Row's index, so you'll need to set the following:

public function configure(): void
{
    $this->setTrAttributes(function($row, int $index) {
        return [
            'default' => true,
            'x-data' => "{ rowIndex: ".($index + 1)." }",
        ];
    });
}

Then your Column can then make use of that "rowIndex" via an Alpine x-text:

Column::make("#")
    ->label(function ($row, $column) {
        return "<span x-text='rowIndex'></span>";
    })
    ->html(),

Note that there's no second parameter on this Column. Setting a field/column that doesn't…

Replies: 1 comment 2 replies

Comment options

lrljoe
Oct 27, 2024
Collaborator Sponsor

You must be logged in to vote
2 replies
@mhmmd-iqbal
Comment options

@lrljoe
Comment options

lrljoe Oct 27, 2024
Collaborator Sponsor

Answer selected by mhmmd-iqbal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants