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
Archibald Grady DVM
1
Sep 2, 1972, 8:42:43 PM
Bertram Schmitt
2
Jun 8, 1999, 11:24:08 PM
Dr. Tyrese Frami III
3
Nov 10, 2025, 2:42:15 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
Jessica Mraz
Nov 18, 1978, 6:44:16 AM
2
Carmella Jones
May 14, 2018, 4:19:21 AM
3
Marquise Stamm III
Oct 25, 2011, 3:42:51 PM

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