Action

Grouping actions

简介

你可以使用 ActionGroup 对象将 Action 分组到一个下拉菜单中。分组可能包含多个 Action 或者其他分组:

use Filament\Actions\Action;
use Filament\Actions\ActionGroup;

ActionGroup::make([
    Action::make('view'),
    Action::make('edit'),
    Action::make('delete'),
])
Action group

此页是关于自定义分组触发按钮及下拉菜单外观。

自定义分组触发按钮样式

打开下拉菜单的按钮能够通过和普通操作相同的方式自定义。触发按钮的所有可用方法可用于自定义分组触发按钮:

use Filament\Actions\ActionGroup;
use Filament\Support\Enums\Size;

ActionGroup::make([
    // Array of actions
])
    ->label('More actions')
    ->icon('heroicon-m-ellipsis-vertical')
    ->size(Size::Small)
    ->color('primary')
    ->button()
Action group with custom trigger style
Table with button action group

Adding a tooltip to the group trigger button

You may add a tooltip to the group trigger button using the tooltip() method:

use Filament\Actions\ActionGroup;

ActionGroup::make([
    // Array of actions
])
    ->tooltip('Actions')
Table with action group tooltip

使用分组按钮设计

除了下拉列表,操作分组也可以渲染成分组按钮。该设计可以有按钮标签也可以没有。要使用此功能,请使用 buttonGroup() 方法:

use Filament\Actions\Action;
use Filament\Actions\ActionGroup;
use Filament\Support\Icons\Heroicon;

ActionGroup::make([
    Action::make('edit')
        ->color('gray')
        ->icon(Heroicon::PencilSquare)
        ->hiddenLabel(),
    Action::make('delete')
        ->color('gray')
        ->icon(Heroicon::Trash)
        ->hiddenLabel(),
])
    ->buttonGroup()
Action group using the button group design

设置下拉菜单的位置

使用 dropdownPlacement() 方法,可以设置下拉菜单相对于触发按钮的位置:

use Filament\Actions\ActionGroup;

ActionGroup::make([
    // Array of actions
])
    ->dropdownPlacement('top-start')
dropdownPlacement() 方法也可以接受函数动态计算其值。你可以将各种 utility 作为参数注入到函数中。 了解更多 utility 注入详情。
Utility 类型 参数 描述
Action group Filament\Actions\ActionGroup $group The current action group instance.
Livewire Livewire\Component $livewire The Livewire component instance.
Eloquent model FQN ?string<Illuminate\Database\Eloquent\Model> $model The Eloquent model FQN for the current action group, if one is attached.
Mounted actions array<Filament\Actions\Action> $mountedActions The array of actions that are currently mounted in the Livewire component. This is useful for accessing data from parent actions.
Eloquent record ?Illuminate\Database\Eloquent\Model $record The Eloquent record for the current action group, if one is attached.
Schema Filament\Schemas\Schema $schema [Action groups in schemas only] The schema object that this action group belongs to.
Schema component Filament\Schemas\Components\Component $schemaComponent [Action groups in schemas only] The schema component that this action group belongs to.
Schema component state mixed $schemaComponentState [Action groups in schemas only] The current value of the schema component.
Schema get function Filament\Schemas\Components\Utilities\Get $schemaGet [Action groups in schemas only] A function for retrieving values from the schema data. Validation is not run on form fields.
Schema operation string $schemaOperation [Action groups in schemas only] The current operation being performed by the schema. Usually create, edit, or view.
Table Filament\Tables\Table $table [Action groups in tables only] The table object that this action group belongs to.
Action group with top placement style

Alternatively, you may let the dropdown position be automatically determined based on the available space using the dropdownAutoPlacement() method:

use Filament\Actions\ActionGroup;

ActionGroup::make([
    // Array of actions
])
    ->dropdownAutoPlacement()

添加操作之间的分隔符

通过使用嵌套 ActionGroup 对象,你可以在不同 Action 分组之间添加分隔线:

use Filament\Actions\ActionGroup;

ActionGroup::make([
    ActionGroup::make([
        // Array of actions
    ])->dropdown(false),
    // Array of actions
])

dropdown(false) 方法将 Action 放在父级下拉菜单中,而不是新的嵌套下拉中。

dropdown() 方法也可以接受函数动态计算其值。你可以将各种 utility 作为参数注入到函数中。 了解更多 utility 注入详情。
Utility 类型 参数 描述
Action group Filament\Actions\ActionGroup $group The current action group instance.
Livewire Livewire\Component $livewire The Livewire component instance.
Eloquent model FQN ?string<Illuminate\Database\Eloquent\Model> $model The Eloquent model FQN for the current action group, if one is attached.
Mounted actions array<Filament\Actions\Action> $mountedActions The array of actions that are currently mounted in the Livewire component. This is useful for accessing data from parent actions.
Eloquent record ?Illuminate\Database\Eloquent\Model $record The Eloquent record for the current action group, if one is attached.
Schema Filament\Schemas\Schema $schema [Action groups in schemas only] The schema object that this action group belongs to.
Schema component Filament\Schemas\Components\Component $schemaComponent [Action groups in schemas only] The schema component that this action group belongs to.
Schema component state mixed $schemaComponentState [Action groups in schemas only] The current value of the schema component.
Schema get function Filament\Schemas\Components\Utilities\Get $schemaGet [Action groups in schemas only] A function for retrieving values from the schema data. Validation is not run on form fields.
Schema operation string $schemaOperation [Action groups in schemas only] The current operation being performed by the schema. Usually create, edit, or view.
Table Filament\Tables\Table $table [Action groups in tables only] The table object that this action group belongs to.
Action groups nested with dividers

设置下拉菜单的宽度

使用 dropdownWidth() 方法,可以为下拉菜单设置宽度。选项对应于 Tailwind 的 max-width 大小。选项包括 ExtraSmallSmallMediumLargeExtraLargeTwoExtraLargeThreeExtraLargeFourExtraLargeFiveExtraLargeSixExtraLargeSevenExtraLarge

use Filament\Actions\ActionGroup;
use Filament\Support\Enums\Width;

ActionGroup::make([
    // Array of actions
])
    ->dropdownWidth(Width::ExtraSmall)
dropdownWidth() 方法也可以接受函数动态计算其值。你可以将各种 utility 作为参数注入到函数中。 了解更多 utility 注入详情。
Utility 类型 参数 描述
Action group Filament\Actions\ActionGroup $group The current action group instance.
Livewire Livewire\Component $livewire The Livewire component instance.
Eloquent model FQN ?string<Illuminate\Database\Eloquent\Model> $model The Eloquent model FQN for the current action group, if one is attached.
Mounted actions array<Filament\Actions\Action> $mountedActions The array of actions that are currently mounted in the Livewire component. This is useful for accessing data from parent actions.
Eloquent record ?Illuminate\Database\Eloquent\Model $record The Eloquent record for the current action group, if one is attached.
Schema Filament\Schemas\Schema $schema [Action groups in schemas only] The schema object that this action group belongs to.
Schema component Filament\Schemas\Components\Component $schemaComponent [Action groups in schemas only] The schema component that this action group belongs to.
Schema component state mixed $schemaComponentState [Action groups in schemas only] The current value of the schema component.
Schema get function Filament\Schemas\Components\Utilities\Get $schemaGet [Action groups in schemas only] A function for retrieving values from the schema data. Validation is not run on form fields.
Schema operation string $schemaOperation [Action groups in schemas only] The current operation being performed by the schema. Usually create, edit, or view.
Table Filament\Tables\Table $table [Action groups in tables only] The table object that this action group belongs to.

控制下拉菜单的偏移量

使用 dropdownOffset() 方法,你可以控制下拉菜单的 offset,默认为 8

use Filament\Actions\ActionGroup;

ActionGroup::make([
    // Array of actions
])
    ->dropdownOffset(16)
dropdownOffset() 方法也可以接受函数动态计算其值。你可以将各种 utility 作为参数注入到函数中。 了解更多 utility 注入详情。
Utility 类型 参数 描述
Action group Filament\Actions\ActionGroup $group The current action group instance.
Livewire Livewire\Component $livewire The Livewire component instance.
Eloquent model FQN ?string<Illuminate\Database\Eloquent\Model> $model The Eloquent model FQN for the current action group, if one is attached.
Mounted actions array<Filament\Actions\Action> $mountedActions The array of actions that are currently mounted in the Livewire component. This is useful for accessing data from parent actions.
Eloquent record ?Illuminate\Database\Eloquent\Model $record The Eloquent record for the current action group, if one is attached.
Schema Filament\Schemas\Schema $schema [Action groups in schemas only] The schema object that this action group belongs to.
Schema component Filament\Schemas\Components\Component $schemaComponent [Action groups in schemas only] The schema component that this action group belongs to.
Schema component state mixed $schemaComponentState [Action groups in schemas only] The current value of the schema component.
Schema get function Filament\Schemas\Components\Utilities\Get $schemaGet [Action groups in schemas only] A function for retrieving values from the schema data. Validation is not run on form fields.
Schema operation string $schemaOperation [Action groups in schemas only] The current operation being performed by the schema. Usually create, edit, or view.
Table Filament\Tables\Table $table [Action groups in tables only] The table object that this action group belongs to.

控制下拉菜单最大高度

使用 maxHeight() 方法,可以设置下拉菜单最大高度,其内容超过此高度则使用滚动条。你可以传入 CSS 长度

use Filament\Actions\ActionGroup;

ActionGroup::make([
    // Array of actions
])
    ->maxHeight('400px')
maxHeight() 方法也可以接受函数动态计算其值。你可以将各种 utility 作为参数注入到函数中。 了解更多 utility 注入详情。
Utility 类型 参数 描述
Action group Filament\Actions\ActionGroup $group The current action group instance.
Livewire Livewire\Component $livewire The Livewire component instance.
Eloquent model FQN ?string<Illuminate\Database\Eloquent\Model> $model The Eloquent model FQN for the current action group, if one is attached.
Mounted actions array<Filament\Actions\Action> $mountedActions The array of actions that are currently mounted in the Livewire component. This is useful for accessing data from parent actions.
Eloquent record ?Illuminate\Database\Eloquent\Model $record The Eloquent record for the current action group, if one is attached.
Schema Filament\Schemas\Schema $schema [Action groups in schemas only] The schema object that this action group belongs to.
Schema component Filament\Schemas\Components\Component $schemaComponent [Action groups in schemas only] The schema component that this action group belongs to.
Schema component state mixed $schemaComponentState [Action groups in schemas only] The current value of the schema component.
Schema get function Filament\Schemas\Components\Utilities\Get $schemaGet [Action groups in schemas only] A function for retrieving values from the schema data. Validation is not run on form fields.
Schema operation string $schemaOperation [Action groups in schemas only] The current operation being performed by the schema. Usually create, edit, or view.
Table Filament\Tables\Table $table [Action groups in tables only] The table object that this action group belongs to.
Edit on GitHub

Still need help? Join our Discord community or open a GitHub discussion

Previous
模态框