Magento 2 : Listing component

Posted . Visible to the public.

Adding Button in listing component as a column

Magento2 provides action columns as selection but sometime we need a button to execute action as per design.
Following example shows how to trigger the existing button event in column button.

/**
     * @param array $dataSource
     *
     * @return array
     */
    public function prepareDataSource(array $dataSource)
    {
        if (isset($dataSource['data']['items'])) {
            foreach ($dataSource['data']['items'] as & $item) {
                $name = $this->getData('name');
                if (isset($item['entity_id'])) {
                    $item[$name]['edit'] = [
                        'callback' => [
                            [
                                'provider' => 'proposal_form.proposal_form.proposal'
                                    . '.stone_modal.create_stone_form_loader',
                                'target' => 'destroyInserted',
                            ],
                            [
                                'provider' => 'proposal_form.proposal_form.proposal'
                                    . '.stone_modal',
                                'target' => 'openModal',
                            ],
                            [
                                'provider' => 'proposal_form.proposal_form.proposal'
                                    . '.stone_modal.create_stone_form_loader',
                                'target' => 'render',
                                'params' => [
                                    'entity_id' => $item['entity_id'],
                                    'proposal_id' => $item['proposal_id'],
                                ],
                            ]
                        ],
                        'href' => '#',
                        'label' => __('Edit'),
                        'hidden' => false,
                    ];


                }
            }
        }

        return $dataSource;
    }
vasan
Last edit
vasan
Posted by vasan to vasan's deck (2022-03-24 16:30)