backend.list.extendColumnsBefore

Provides an opportunity to modify the columns of a List widget before the columns are created.

Example usage:

Event::listen('backend.list.extendColumnsBefore', function ($listWidget) {
    // Only for the User controller
    if (!$listWidget->getController() instanceof \Backend\Controllers\Users) {
        return;
    }

    // Only for the User model
    if (!$listWidget->model instanceof \Backend\Models\User) {
        return;
    }

    // Add a column in first position
    $listWidget->columns = array_merge([
        'myColumn' => [
            'type' => 'text',
            'label' => 'My Column',
        ],
    ], $listWidget->columns);
});

Or

$listWidget->bindEvent('list.extendColumnsBefore', function () use ($listWidget) {
    // Only for the User controller
    if (!$listWidget->getController() instanceof \Backend\Controllers\Users) {
        return;
    }

    // Only for the User model
    if (!$listWidget->model instanceof \Backend\Models\User) {
        return;
    }

    // Add a column in first position
    $listWidget->columns = array_merge([
        'myColumn' => [
            'type' => 'text',
            'label' => 'My Column',
        ],
    ], $listWidget->columns);
});

Usage

Triggers

Class or file Line
Backend\Widgets\Lists 849
Copyright © 2024 Winter CMS