Yii2 Components - Data tables

Data tables

DataTable is inherited from yii\grid\GridView. It is used to display data using MDC data table.
vip9008\MDC\components\DataTable

Usage

A basic usage looks like the following:

<?php
echo DataTable::widget([
    'dataProvider' => $dataProvider,
    'columns' => [
        'name',
        'id',
        'created_at:datetime',
    ],
]);
?>

The above code will render a data table like the following:

Name ID Created at
Drew Von
1
Dec 26, 1982, 12:20:48 PM
Noelia Emard DVM
2
Mar 22, 2002, 1:35:15 PM
Dr. Pasquale Braun
3
May 24, 1977, 6:33:00 AM

Customization options

Data table can be further customized by adding a header and action buttons.

<?php
echo DataTable::widget([
    'dataProvider' => $dataProvider,
    [
        'title' => 'Customers list',
        // Alternative header title configuration
        // 'title' => [
        //     'content' => 'Customers list',
        //     'options' => [...], HTML attributes for header title
        // ],
        'actions' => [
            '<button class="material-icon">filter_list</button>',
            '<button class="material-icon">more_vert</button>',
        ],
        // 'options' => [...], HTML attributes for table header container
    ],
    'columns' => [
        'id',
        'name',
        'created_at:datetime',
    ],
]);
?>
Customers list
ID Name Created at
1
Prof. Nikolas Miller
Mar 23, 2022, 2:38:14 PM
2
Annabelle Donnelly
Jun 15, 1974, 5:48:07 PM
3
Albert Shanahan
Feb 17, 1999, 3:32:21 AM

Other options are inherited from the parent class. see yii\grid\GridView.