Skip to content

Buttons ⏹️

In general we use Button in configureActions() method of Controller Here.

php
   public function configureActions(): iterable
    {
        return [
            ButtonField::init(ButtonField::DETAIL)->linkToRoute('product.show'),
            ButtonField::init(ButtonField::EDIT)->linkToRoute('product.edit'),
            ButtonField::init(ButtonField::DELETE)->linkToRoute('product.delete'),
            ButtonField::init('new', 'new')->linkToRoute('product.create')->createAsCrudBoardAction(),
            ButtonField::init('submit')->createAsFormSubmitAction(),
            ButtonField::init('cancel')->linkToRoute('product.list')->createAsFormAction(),
            ButtonField::init('back')->linkToRoute('product.list')->createAsShowAction()->setIcon('fa-arrow-left'),
        ];
    }

Bootstrap Modal

If we make the button as:

php
ButtonField::init('btn_popup', 'Popup')->linkToRoute('product.show')->asModal(),

It will popup using Bootstrap 4 modal.

Display As Button

If we put a button like below:

php
ButtonField::init('Test Button', 'Test')->createAsCrudBoardAction()->displayAsButton()

It will add a new button in the top right corner of the grid table.

Please keep in mind

If you use ->displayAsButton(), it will populate with the <button></button> tag.

Defining Button Positions

There are several button positions that we can define using the following methods:

createAsCrudBoardAction

Adds the button to the top right corner of the grid table.

createAsFormSubmitAction()

Adds the button as a form submit button.

createAsFormAction()

Adds the button to the form, typically for actions like cancel or other form-related actions.

createAsFilterAction()

Adds the button to the filter form for general actions like Reset Button.

createAsFilterSubmitAction()

Adds the button as a search/submit button for the filter form.

createAsShowAction()

Adds the button to the item view for specific actions related to the item being viewed.

Examples

Adding a Button in the Grid Action Column

If we put a button like below

php
ButtonField::init('btn_popup', 'Popup')->linkToRoute('product.show'),

It will add a new button in the Action column of Grid Table

image

Adding a Button to the Top Right Corner of the Grid Table

If we put a button like below:

php
ButtonField::init('Test Button', 'Test')->createAsCrudBoardAction()

It will add a new button in the top right corner of the grid table.

Customizing Filter Search and Reset Buttons

There are also two different buttons that we can customize for the filter: the Search button and the Reset button.

Search Button

php
ButtonField::init('find', 'Find')->createAsFilterSubmitAction()

Reset Button

php
ButtonField::init('find', 'Find')->linkToRoute('product.list')->createAsFilterAction(),

This will create a reset button that clears the filter form and redirects to the product list.

Developed By ❤️ Taki Elias