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. Emmanuelle O'Kon DVM
1
May 17, 1999, 1:51:34 PM
Hallie Larson DVM
2
Dec 23, 1992, 11:04:41 AM
Dalton Simonis
3
May 31, 2005, 4:08:23 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
Ms. Marcelina Walker Sr.
Nov 15, 1982, 8:26:45 AM
2
Mr. Elvis Kozey I
Mar 1, 1988, 9:12:25 AM
3
Murl Hessel
May 1, 2021, 9:34:54 AM

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