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
Ms. Krystal Stamm DDS
1
Jun 30, 1983, 12:57:47 AM
Zackery Rolfson
2
May 2, 2002, 1:54:14 AM
Ms. Fabiola Renner
3
May 28, 1979, 1:10:31 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
Jayden Johnson Sr.
May 23, 2008, 2:24:28 AM
2
Enrico Barrows
Mar 19, 1983, 11:12:17 AM
3
Prof. Osvaldo Koch III
May 4, 1997, 1:38:22 AM

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