Expandable Table Row

Expandable Table Row in Action

Provides an easy way to append extra data to each row of your resource tables.

Installation

You can install the package via composer:

composer require digital-creative/expandable-table-row

Basic Usage

To use the new functionality, all you need to do is add the ->expandableRowData() method to your field definition and return any class that extends Nova Field or an array of fields.

class UserResource extends Resource
{
    public function fields(NovaRequest $request): array
    {
        return [
            //...
            Text::make('First Name')->expandableRowData(function () {
                return [
                    Line::make(null)->displayUsing(fn () => 'Name')->asSubTitle(),
                    Text::make('Full Name', fn (User $user) => sprintf('%s %s',$user->first_name, $user->last_name))->copyable(),
                    Text::make('Email')->copyable(),
                ];
            }),
    
            Text::make('Last Name')->expandableRowData(function () {
                return [
                    Line::make(null)->displayUsing(fn () => 'Address')->asSubTitle(),
                    Text::make('Country'),
                    Text::make('Address', fn (User $user) => sprintf(
                        '%s, %s, %s - %s', $user->city, $user->state, $user->address, $user->zipcode
                    ))->copyable(),
                ];
            }),
            //...          
        ];
    }
}

Settings

You can configure several options by using ->expandableRowOptions(). Below, you’ll find an explanation of each.

public function fields(NovaRequest $request): array
{
    return [
        Text::make('...')->expandableRowOptions([
            'span' => 2, // This makes the metadata take X much more columns.
            'expanded_by_default' => true, // This makes the table row start expanded by default.
            'preallocate_column_width' => true, // This will avoid the table column shifting when expanding / collapsing.
        ]),
    ];
}

License

The MIT License (MIT). Please see License File for more information.

GitHub

View Github