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
Dr. Lizzie Senger DVM
1
Sep 28, 1992, 7:34:51 AM
Bradley Bradtke
2
Apr 3, 2021, 7:40:59 PM
Beth Monahan
3
Sep 18, 1972, 1:51:04 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
Dr. Evan Stanton MD
Oct 14, 1974, 12:27:14 AM
2
Alexandro Kerluke
Jun 11, 2002, 8:59:06 AM
3
Golda Bins
Mar 9, 1977, 2:55:28 AM

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