Programmatic Solution to Add Delete Action Column in Magento 2: 1. Change code in Showdata.php file at app\code\Cozmot\Extension\Block\
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
<?php
namespace Cozmot\Extension\Block;
use Magento\Framework\View\Element\Template;
use Magento\Backend\Block\Template\Context;
use Cozmot\Extension\Model\ResourceModel\Extension\CollectionFactory;
class Showdata extends Template
{
public $collection;
public function __construct(Context $context, CollectionFactory $collectionFactory, array $data = [])
{
$this->collection = $collectionFactory;
parent::__construct($context, $data);
}
public function getCollection()
{
return $this->collection->create();
}
public function getDeleteAction()
{
return $this->getUrl(‘extension/index/delete’, [‘_secure’ => true]);
}
}
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
<?php
$collection = $block->getCollection();
if ($collection->count()) {
?>
<div class=“table-wrapper orders-history”>
<table class=“data table table-order-items history” id=“my-orders-table”>
<caption class=“table-caption”><?php echo __(‘Grid Record’) ?></caption>
<thead>
<tr>
<th scope=“col” class=“col id”><?php echo __(‘ID’) ?></th>
<th scope=“col” class=“col name”><?php echo __(‘Name’) ?></th>
<th scope=“col” class=“col email”><?php echo __(‘Email’) ?></th>
<th scope=“col” class=“col telephone”><?php echo __(‘Telephone’) ?></th>
<th scope=“col” class=“col createat”><?php echo __(‘Created At’) ?></th>
<th scope=“col” class=“col action”><?php echo __(‘Action’) ?></th>
</tr>
</thead>
<tbody>
<?php
foreach ($collection as $item): ?>
<tr>
<td data–th=“<?= $block->escapeHtml(__(‘ID’)) ?>“ class=“col id”>
<?php echo $item->getId() ?>
</td>
<td data–th=“<?= $block->escapeHtml(__(‘Name’)) ?>“ class=“col name”>
<?php echo $item->getName() ?>
</td>
<td data–th=“<?= $block->escapeHtml(__(‘Email’)) ?>“ class=“col email”>
<?php echo $item->getEmail() ?>
</td>
<td data–th=“<?= $block->escapeHtml(__(‘Telephone’)) ?>“ class=“col telephone”>
<?php echo $item->getTelephone() ?>
</td>
<td data–th=“<?= $block->escapeHtml(__(‘Created At’)) ?>“
class=“col title”><?php echo date(‘Y-m-d’, strtotime($item->getCreatedAt())); ?>
</td>
<td data–th=“<?= $block->escapeHtml(__(‘Action’)) ?>“ class=“col delete”>
<a href=“<?php echo $block->getDeleteAction() . ‘id/’ . $item->getId(); ?>“><?php echo __(‘Delete’) ?></a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php
}
?>
|