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
Eldred Beer
1
Feb 15, 2018, 9:59:40 AM
Gage Corkery DVM
2
Dec 24, 2005, 9:24:31 PM
Lexi Green
3
Feb 21, 1993, 10:02:23 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
Beth Luettgen
Aug 19, 2016, 7:41:40 AM
2
Jamaal Runolfsdottir
Dec 5, 1979, 7:32:20 PM
3
Dr. Celestine Nader
Aug 22, 2015, 11:48:54 AM

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