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
Enola Raynor
1
Jul 14, 1976, 8:03:23 AM
Dr. Devin Boehm DDS
2
Oct 15, 1986, 12:42:19 PM
Agustina Konopelski DDS
3
Jan 25, 2009, 4:54:33 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
Marta Haley
Oct 31, 2023, 11:06:47 PM
2
Lucas Bartoletti V
Sep 5, 1976, 5:37:39 PM
3
Reymundo Hegmann
Aug 18, 1975, 5:50:14 PM

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