This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

noxioustoo34847
noxioustoo34847

I want a column like the first one. It's not ID. If I click on a filter I want to this column count the records.

Drag Racing

maraerben
maraerben

Maybe you could define your own column type with static counter variable to count rows in Plugin.php.

E.G.

public function registerListColumnTypes()
{
    return [
        'row_number' => function () {
            static $counter = 1;
            return $counter++;
        }
    ];
}

And in your columns.yaml file:

no:
    label: No
    type: row_number

Last updated

maraerben
maraerben

Or just implement getRowNumberAttribute() method in your model.

public function getRowNumberAttribute()
{
    static $counter = 1;
    return $counter++;
}

And in your columns.yaml:

no:
    label: No
noxioustoo34847
noxioustoo34847

maraerben said:

Maybe you could define your own column type with static counter variable to count rows in Plugin.php.

E.G.

public function registerListColumnTypes()
{
   return [
       'row_number' => function () {
           static $counter = 1;
           return $counter++;
       }
   ];
}

And in your columns.yaml file:

no:
   label: No
   type: row_number

Thank you very much! It's working, but if I change the position of the row_number column (set it first) I get an error that such column is not found. It's trying to execute the query - ORDER BY row_number. This error appears only if I set the column on the first position or if I try to sort the column (even if sortable attribute is specified).

Last updated

1-4 of 4

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.