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
Letha Wolff DDS
1
Aug 28, 1983, 8:25:32 AM
Prof. Raven Wolf V
2
May 22, 2013, 4:57:50 PM
Ada Brown
3
Aug 20, 1973, 5:33:32 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
Prof. Akeem Thiel Jr.
Mar 27, 2024, 12:46:45 PM
2
Mable Watsica
Oct 5, 1974, 7:53:24 AM
3
Heaven Pollich
Sep 23, 1991, 9:28:11 PM

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