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
Cheyenne Collins
1
Dec 10, 1980, 1:57:06 AM
Prof. Brent Howe
2
Sep 25, 1991, 10:22:05 AM
Susan Sanford
3
Feb 9, 1994, 4:47:08 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
Ms. Melyssa Willms
Oct 7, 2013, 8:37:45 AM
2
Dawn Wilderman
Dec 9, 2004, 1:20:05 AM
3
Miss Jewel Goldner MD
Oct 19, 2002, 7:16:19 AM

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