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
Dr. Merl Koch
1
Mar 17, 2010, 8:51:01 AM
Mia O'Hara
2
Aug 31, 1995, 8:57:51 AM
Miss Vada Schiller DVM
3
Dec 3, 1985, 7:58:41 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
Grayson Funk III
Aug 8, 2025, 1:11:40 PM
2
Madelynn Gutkowski
Mar 17, 1977, 9:34:38 PM
3
Adelle Reichel
Jun 21, 1979, 9:51:33 PM

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