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
Jimmy White
1
Mar 15, 2016, 6:36:52 PM
Prof. Davonte Wilkinson I
2
Oct 20, 1995, 9:21:53 AM
Alba Greenholt
3
Mar 23, 2008, 1:50:30 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
Tierra Bednar
Jul 18, 1989, 8:58:10 AM
2
Deonte Dietrich
Apr 24, 1976, 1:16:09 PM
3
Prof. Xavier Konopelski III
Jan 1, 2009, 4:32:19 AM

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