deniskoronets / Laravel-GridView

Laravel package which allows to render cool tables
https://deniskoronets.github.io/Laravel-GridView/
20 stars 7 forks source link

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

Open pamungkasandono opened 1 month ago

pamungkasandono commented 1 month ago

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...
    ],
    1. 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 commented 1 month ago

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?