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
Diego Jerde I
1
Apr 19, 2019, 7:10:57 PM
Teagan Mraz
2
Sep 19, 2004, 12:59:12 PM
Riley Rutherford
3
Feb 20, 1997, 4:05: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
Enos Collins
Oct 27, 1991, 7:45:56 PM
2
Percy Ryan
Apr 3, 1981, 4:12:52 AM
3
Lance Kautzer I
Apr 22, 1971, 8:38:10 AM

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