Skip to content
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

How to Implement Serial Number Column in Laravel GridView? #52

Open
pamungkasandono opened this issue Oct 13, 2024 · 1 comment
Open

Comments

@pamungkasandono
Copy link

I'm trying to implement a serial number column in the Laravel GridView. I would like to know the best approach to achieve this.

Here are my questions:

  1. Using SerialColumn:

    • In Yii2, we can easily add a serial number column using ['class' => 'yii\grid\SerialColumn']. This automatically generates a serial number for each row.

    • How can we achieve similar functionality in Laravel GridView?

    Example in Yii2:

    'columns' => [
        ['class' => 'yii\grid\SerialColumn'],
        'username',
        // other columns...
    ],
    
  2. Custom Function Parameters:

    • Is it possible to provide additional parameters in the function used for the value attribute in the columns? For instance, I want to use the index to determine the serial number.

    Example Implementation:

    [    
        'header' => 'No',
        'value' => function ($model, $key, $index, $column) {
            // Using $index to determine the serial number
            return $index + 1;
       },
    ],
    

I appreciate any guidance on how to implement this feature effectively.

Thank you!

@msharifi68
Copy link

Laravel-GridView documents: In case of CallbackColumn usage, instead of value pass \Closure which has a single argument - $model or $row to get access to current item.

now how to use $index and $key argument?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants