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
Charlene Weissnat
1
Jul 15, 2015, 3:06:04 PM
Selina Hansen
2
Nov 18, 2008, 2:51:53 PM
Prof. Jordi Daniel
3
May 11, 1971, 1:23:52 PM

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
Audie Quitzon
Nov 26, 1996, 6:47:47 PM
2
Prof. Grayce Bartell
Oct 31, 2021, 3:41:23 AM
3
Bart Huels
Jul 12, 1985, 1:44:27 PM

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