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
Kali Lubowitz
1
Jan 14, 1999, 11:32:11 AM
Seth Harvey PhD
2
Apr 24, 1974, 9:01:49 PM
Garland Franecki MD
3
Apr 14, 2022, 2:16:47 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
Miss Enola Gislason V
Dec 21, 2016, 7:59:15 PM
2
Claude Greenfelder
May 25, 2002, 4:08:33 AM
3
Providenci Marks II
Jul 22, 1972, 1:25:34 AM

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