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
Lura Will I
1
Mar 1, 2016, 4:43:45 PM
Maximilian Langosh
2
Oct 4, 2010, 6:43:29 PM
Prof. Eda Thiel DDS
3
Oct 17, 1987, 6:27:03 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
Curt Aufderhar
Oct 26, 1977, 7:23:37 PM
2
Clyde Schoen
Jan 30, 2016, 5:36:55 PM
3
Yazmin Bernhard
Apr 8, 2006, 12:09:33 AM

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