The yii2-dynagrid module is a great complementary addition to the kartik-v/yii2-grid module, enhancing it with personalization features. It turbo charges your grid view by making it dynamic and personalized for each user. It allows users the ability to set and save their own grid configuration. The major features provided by this module are:
DynaGridStoreobject to manage dynagrid personalizations independent of storage. One of the following storage options are made available to store the personalized grid configuration:
Note: This extension depends on the kartik-v/yii2-grid extension which in turn depends on the yiisoft/yii2-bootstrap extension. Check the composer.json for this extension's requirements and dependencies. Note: Yii 2 framework is still in active development, and until a fully stable Yii2 release, your core yii2-bootstrap packages (and its dependencies) may be updated when you install or update this extension. You may need to lock your composer package versions for your specific app, and test for extension break if you do not wish to auto update dependencies.
The latest version of the module is v1.2.0 released on 25-Oct-2014. Refer the CHANGE LOG for details.
With v1.2.0, the Dynagrid is revamped to include a
DynaGridStore object and ability to save, update, or delete grid personalizations including grid filter and sort.
With v1.1.0, the DynaGrid includes Pjax support. To enable Pjax processing, set
gridOptions['pjax'] property to
true and control pjax behavior using
The preferred way to install this extension is through composer.
Note: Before you install, remember to check if the
minimum-stabilityis set to
devin your composer.json file in the application root.
$ php composer.phar require kartik-v/yii2-dynagrid "*"
require section of your
Setup the module in your Yii configuration file with a name
dynagrid as shown below. In addition, you must also register the
gridview module as described in the yii2-grid documentation.
'modules' => [ 'dynagrid' => [ 'class' => '\kartik\dynagrid\Module', // other settings (refer documentation) ], 'gridview' => [ 'class' => '\kartik\grid\Module', // other module settings ], ],
The DynaGrid widget can be used to render the personalized & dynamic version of
kartik\Grid\GridView in the following way:
use kartik\dynagrid\DynaGrid; use kartik\grid\GridView; $columns = [ ['class'=>'kartik\grid\SerialColumn', 'order'=>DynaGrid::ORDER_FIX_LEFT], 'id', 'name', [ 'attribute'=>'publish_date', 'filterType'=>GridView::FILTER_DATE, 'format'=>'raw', 'width'=>'170px', 'filterWidgetOptions' => [ 'pluginOptions' => ['format' => 'yyyy-mm-dd'] ], ], [ 'class'=>'kartik\grid\BooleanColumn', 'attribute'=>'status', 'vAlign'=>'middle', ], [ 'class'=>'kartik\grid\ActionColumn', 'dropdown'=>false, 'order'=>DynaGrid::ORDER_FIX_RIGHT ], ['class'=>'kartik\grid\CheckboxColumn', 'order'=>DynaGrid::ORDER_FIX_RIGHT], ]; echo DynaGrid::widget([ 'columns' => $columns, 'storage'=>DynaGrid::TYPE_COOKIE, 'theme'=>'panel-danger', 'gridOptions'=>[ 'dataProvider'=>$dataProvider, 'filterModel'=>$searchModel, 'panel'=>['heading'=>'<h3 class="panel-title">Library</h3>'], ] ]);
Tip: You need to be careful, in case you are using the new
\kartik\grid\FormulaColumnin your grid layout. The reordering of columns by users will render your formulae invalid, since the column indices will change. It is recommended, you set the order of all such formulae columns and its dependencies to the
DynaGrid::ORDER_FIX_LEFT, so that such column positions are pre-fixed.
yii2-dynagrid is released under the BSD 3-Clause License. See the bundled
LICENSE.md for details.