Coder Social home page Coder Social logo

kartik-v / yii2-dynagrid Goto Github PK

View Code? Open in Web Editor NEW
74.0 12.0 66.0 460 KB

Turbo charge the Yii 2 GridView with personalized columns, page size, and themes.

Home Page: http://demos.krajee.com/dynagrid

License: Other

PHP 95.63% CSS 0.38% JavaScript 3.99%

yii2-dynagrid's Introduction

Krajee Logo
yii2-dynagrid
Donate       kartikv

Latest Stable Version Latest Unstable Version License Total Downloads Monthly Downloads Daily Downloads

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:

  • Personalize, set, and save grid page size at runtime. You can set the minimum and maximum page size allowed.
  • Personalize, set, and save grid data filters at runtime. A user can define and save his/her own personalized grid data filters.
  • Personalize, set, and save grid column sorts at runtime. A user can define and save his/her own personalized grid column sorts.
  • Personalize the grid columns display through drag and drop. Reorder grid columns and set the visibility of needed columns, and allow users to save this setting. Control which columns can be reordered by users through predefined columns setup. Predetermine which of your desired columns will be always fixed to the left or right by default.
  • Personalize grid appearance and set the grid theme. This will offer advanced customization to the grid layout. It allows users to virtually style grid anyway they want, based on how you define themes and extend them to your users. Since the extension uses the yii2-grid extension,it offers all the styling options the yii2-grid extension provides, including the various grid column enhancements, bootstrap panels, and other grid styles. This will allow you to easily setup themes for users in many ways. You have an ability to setup multiple themes in your module configuration, and allow users to select one of them. The extension by default includes some predefined themes for you to get started.
  • Allow you to save the dynamic grid configuration specific to each user or global level. Implements a DynaGridStore object to manage dynagrid personalizations independent of storage. One of the following storage options are made available to store the personalized grid configuration:
    • Session Storage (default)
    • Cookie Storage
    • Database Storage
  • The extension automatically validates and loads the saved configuration based on the stored settings.

NOTE: This extension depends on the kartik-v/yii2-grid and kartik-v/yii2-sortable extensions which in turn depends on the yiisoft/yii2-bootstrap extension. Check the composer.json for this extension's requirements and dependencies.

Latest Release

Refer the CHANGE LOG for details on changes to various releases.

  • 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 gridOptions['pjaxSettings'].

How to contribute via a pull request?

Refer this git workflow for contributors.

Demo

You can see detailed documentation, view the API Code Documentation or view a complete demo on usage of the extension.

Installation

The preferred way to install this extension is through composer.

Note: Check the composer.json for this extension's requirements and dependencies. Read this web tip /wiki on setting the minimum-stability settings for your application's composer.json.

Either run

$ php composer.phar require kartik-v/yii2-dynagrid "@dev"

or add

"kartik-v/yii2-dynagrid": "@dev"

to the require section of your composer.json file.

Usage

Module

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
    ],
],

DynaGrid

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>'],
    ],
    'options'=>['id'=>'dynagrid-1'] // a unique identifier is important
]);

Warning: You need to be careful, in case you are using the new \kartik\grid\FormulaColumn in 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 DynaGrid::ORDER_FIX_LEFT, so that such column positions are pre-fixed.

License

yii2-dynagrid is released under the BSD-3-Clause License. See the bundled LICENSE.md for details.

yii2-dynagrid's People

Contributors

antoniom avatar aslatius avatar derekisbusy avatar djbuch avatar dvdkrgr avatar edofre avatar emanonenoon avatar geoffry304 avatar gvasilopulos avatar ittaskeu avatar kartik-v avatar kevocde avatar leifox avatar lukascernydis avatar maczkop avatar matteo-cerioni avatar maz0717 avatar monghuz avatar nidgetgod avatar nikolaystrikhar avatar pgyf avatar philippfrenzel avatar rafaelwithoeft avatar semako avatar stivehu avatar theill11 avatar thelfensdrfer avatar tonisormisson avatar werewolf8904 avatar xzaero avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

yii2-dynagrid's Issues

Enhance default settings controls in panel and dialog box

I suggest changing the default grid personalization configuration dialog box to make the column settings section part consisting of a single column of all field names with check boxes beside each field to show/hide it instead of two columns and the drag and drop for sorting them. This would make it more touch-friendly and more intuitive. It would be also better for touch devices if the sorting could be done by up/down buttons in each field element.

Probably also move the whole column settings section form the current dialog box to a drop down menu or separate dialog box popping from a button in the panel area and move the number of rows setting to a drop down list with fixed settings in the panel, and add a drop down list for filters.

This would make the grid more readily usable out of the box.

Class 'kartik\sortable\Sortable' not found

After installation error:

PHP Fatal Error – yii\base\ErrorException
Class 'kartik\sortable\Sortable' not found

In file /vendor/kartik-v/yii2-dynagrid/dynagrid/views/config.php

Order of visible columns (DB) in the personalize modal.

grid
grid2

Order of columns saved on DB (CNPJ, Endereço, Nome Fantasia).

Data saved on DB

{"page":"10","keys":["7ca9c5d6","e3568eca","017e9e28"],"theme":"panel-primary"}

The code:

$columns = [
    'nome_fantasia',
    'cnpj',
    [
        'label' => 'Endereço',
        'attribute' => 'endereco',
        'value' => 'endereco.endereco',
        'options' => ['visible' => 'hidden'],
    ],
];

echo DynaGrid::widget([
    'storage' => 'db',
    'columns' => $columns,
    'options' => ['id' => 'lista_escritorio_grid'], // um identificador único é importante!
    'userSpecific' => false,
    'toggleButton' => ['label' => 'Personalizar'],
    'theme' => 'panel-primary',
    'gridOptions' => [
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'showPageSummary'=> false,
        'panel' => [
            'heading' => '<h3 class="panel-title">Listas</h3>',
            //'after' => '{export}',
        ],
    ],
]);

Configuration module in main.php

'dynagrid' => [
        'class' => 'kartik\dynagrid\Module',
        'dbSettings' => [
            'tableName' => 'psw_configuracao',
            'idAttr' => 'chave',
            'dataAttr' => 'valor',
        ],
        'i18n' => [
            'class' => 'yii\i18n\PhpMessageSource',
            'basePath' => '@kvdynagrid/messages',
            'forceTranslation' => true
        ],
    ],
    'gridview' => [
        'class' => 'kartik\grid\Module',
    // other module settings
    ],

What's wrong?

Only variables should be passed by reference

Falls the following error:

 PHP Strict Warning – yii\base\ErrorException
Only variables should be passed by reference

    1. in /var/www/erp.avalon.kz.dev/vendor/kartik-v/yii2-dynagrid/dynagrid/DynaGrid.php at line 637

We can fix it as follows:

$class = explode('\\', $class);
$label = Inflector::camel2words(end($class));

But then falls a critical error: "502 Bad Gateway". Falls a backend,
I use Debian, nginx + php5-fpm, php55.
The error occurs in the function applyColumns().
Fixed:

if (isset($column['order']) && isset($column['visible'])) {
    unset($column['order'], $column['visible']);
}

If necessary, I can make pull request.

Help (DynaGrid rendered on modal)

Hello, I need a help.

I got two situations (render with modal window or normal window).

On normal window, it worked as usual.
But in modal window, when open the personalize (modal), is open in the same modal, and on click apply button, all modals are closed and they are redirected to another page (the same page rendered by the last ajax requisition).

I would like to:
When the request is comming from ajax, only the modal should be reloaded. is it possible?

How can i do it?

-------------------------------------------------

And the new feature (showPersonalize), if set it to false, the export button becomes hidden too..
Is it possible to set the parameter (showPersonalize false), showing the export button only?

I do apologize for the many doubts and suggestions.

Best Regards,

Allow empty keys on DB

Data saved on DB:

{"page":"10","keys":[""],"theme":"panel-primary"}

bg

This way solve the problem:
foreach ($this->_visibleKeys as $key) {
    if(ArrayHelper::keyExists($key, $visibleSettings)) {
        $this->_visibleColumns[] = $visibleSettings[$key];
    }
}

Class 'kartik\widgets\DynaGrid' not found

I followed the configuration steps (details later), but I get this error message.

After a successfully composer update I see yii2-dynagrid folder inside kartik-v folder. If I am right there should be a DynaGrid.php file inside kartik-v/widgets folder, but there isn't.

Maybe I forget to config something, but I lost in debuging :(

My config steps were the followings:
I inserted the following into web.php module section.

'dynagrid'=> [
        'class'=>'\kartik\dynagrid\Module',
        'class'=>'yii\i18n\PhpMessageSource',
        'basePath'=>'@kvdynagrid/messages',
        'forceTranslation'=>true
    ],
    'gridview'=> [
        'class'=>'\kartik\grid\Module',
        'class'=>'yii\i18n\PhpMessageSource',
        'basePath'=>'@kvdynagrid/messages',
        'forceTranslation'=>true
    ],

In my index.php I added these namespaces

use yii\helpers\ArrayHelper;
use kartik\helpers\Html;
use kartik\grid\GridView;
use kartik\widgets\DynaGrid;

After the $gridColums configuration I called the widget. Not that I get the error message for the first line of the following code.

<?= DynaGrid::widget([
        'columns' => $gridColumns,
        'storage'=>DynaGrid::TYPE_COOKIE,
        'theme'=>'panel-danger',
        'gridOptions'=>[
            'dataProvider'=>$dataProvider,
            'filterModel'=>$searchModel,
            'gridOptions'=>[
                'dataProvider'=>$dataProvider,
                'filterModel'=>$searchModel,
                'panel'=>['heading'=>'<h3 class="panel-title">Library</h3>'],
            ]
        ]
    ]); ?>

Get Selected Rows

Kartik,

Sorry to open an issue for this but I'm trying for almost month already and with no success.
I need to get the selected rows (checkbox) so I can export or do whatever I can do with all the selected rows.

Can you help me please?

Relational column.

your extensions are beautiful. what about TO enhance your grid with a relational column like the one in yiiwheels? in this manner we can display a child inside the parent grid. in this grid we can display data from a related table or other hidden data from parent grid.

configuration window and suggestion

Hello,
on my application, after post of the configurations (columns, etc...)
the configuration window is not working correctly...
...look the images...

NO $_POST

dyna_no_post1
dyna_no_post2

AFTER $_POST CONFIGURATION

dyna1
dyna2

Another suggestion if possible:

Private variables, alter them to protected.

In my application i have custom configurations and i extend your dynagrid... is not generic, it is specific of my application.
The private variables generate error when extending the class (obviously) so I alter them to protected.

Translation

Hi:

I have a message translate to spanish. If you think could be interesant tell me where to upload.

Thanks for a great work.

Add Model as a new storage option

I suggest adding Model as a storage option to the current ones. The developer would pass models inhered from DynaGridConfig and DynaGridSettings. My understanding is that there's currently no direct way to interrupt the above models' data moved from/to the grid and the database to perform any extra processing. For example, to filter the retrieved user column set against a permissions list set by the admin as those permission could be updated after the user settings were saved, so the user does not see columns/data he's no longer supposed to see. There are also other useful uses for this.

Please add ajax fontsize selection in toolbar

Some times we try to minimize the fontsize in case we have lots of columns need to display in grid.
I am using my customized ajax function to dyna adjust fontsize for dynagrid now.

Would suggest you direct provoide this function for dynagrid widget.
Such as a dropdown list allow user to select huge/large/normal/small/tiny(140%/120%/100%/85%/70%) fontsize and then dynagrid change its all fontsize style immediately with ajax.

before and after dont work

Hi 👍
If i want to put more buttons in grid a can use 👍
'panel' => [
'heading'=>'

'.Html::encode($this->title).'

',
'type'=>'info',
'before'=>Html::a('

But in Dynagrid after and before dont work in panel.

Only Sort instance, configuration array or false is allowed.

368369370371372373374375376377378379380 'id' => $this->options['id'],
'storage' => $this->storage,
'userSpecific' => $this->userSpecific
]);
$this->prepareColumns();
$this->configureColumns();
$this->applyGridConfig();
$this->_isPjax = ArrayHelper::getValue($this->gridOptions, 'pjax', false);
if ($this->_isPjax) {
$this->gridOptions['pjaxSettings']['options']['id'] = $this->_pjaxId;
}
$this->initGrid();

New property `allowPageSetting`

New boolean property allowPageSetting that will allow you to display the pagination widget if needed. If pagination is set to false this will be automatically set to false.

Disable themes?

Is there a way to disable the simple-* themes without removing them in the base?
remove simple

Undefined index: filterModel

If I use DynaGrid without filterModel, I get the following message:

PHP Notice – yii\base\ErrorException

Undefined index: filterModel
1. in /home/evgen-d/project/application/vendor/kartik-v/yii2-dynagrid/DynaGrid.php at line 642

    /**
     * Applies the grid filter
     */
    protected function applyFilter()
    {
        $class = get_class($this->gridOptions['filterModel']);
        if (!empty($this->_detailConfig[DynaGridStore::STORE_FILTER]) && empty($_GET[$class])) {
            $attributes = $this->_detailConfig[DynaGridStore::STORE_FILTER];
            $searchModel = $this->gridOptions['filterModel'];
            $searchModel->setAttributes($attributes);
            $this->gridOptions['filterModel'] = $searchModel;
            $this->initDataProvider($searchModel);
        }
    }

Grid not saving when allowThemeSetting is false

Kartik,

I did the update by getting the code from dev-master but when I put 'allowThemeSetting' => false, than the grid doesn't save my changes that I did on the Personalize Grid Configuration screen.
If I remove allowThemeSetting than it works.

Suggestion Personalize Button

Suggestion
Add a attribute 'showPersonalize' for example, with true/false to show or no the personalize button (that is where located the configurations grid, visible columns, ...).

It's utilized for user permission level.

Regards

Add support for Pjax

Use the new ability of yii2-grid support for pjax. Enhance extension to autoinitialize all jquery plugins when gridOptions['pjax'] is set to true.

Problems with displaying summary

The following code:

<?= DynaGrid::widget([
    ...
    'gridOptions' => [
        ...
        'showPageSummary' => true,
    ],    
]) ?>

generates this HTML output:

<tfoot>
    <tr class="kv-page-summary warning">
        <td style="width:50px;" class="kv-align-center kv-align-middle">&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
    </tr>
</tfoot>

What's wrong?

'before' values not working after last commit

I think after the last change does not work "before" value in panel into gridOptions.
if change ( into file DynaGrid.php ) $this->gridOptions = ArrayHelper::merge($this->gridOptions, $theme);
to $this->gridOptions = ArrayHelper::merge($theme, $this->gridOptions); works !!

otherwise 'before' cannot displayed
this merge takes 'before' from $theme variant and ignore [panel][before].
probably not working and in your demo.

Migrate Script for tables

Hi,

can you pls. add a migrate script for the additional needed tables and columns, as many people use migrate functionality to deploy solutions and add them to migrate environment...

Thanks Philipp

setting pagination and sort to false does not work in dynagrid

I'm trying to disable sort and pagination, as documented here: http://www.yiiframework.com/doc-2.0/yii-data-basedataprovider.html#$pagination-detail

If I use a yii2 gridview, this works, in a dynagrid this throws an error. Here is the code:

$SampleSearchModel = new SampleSearch();
$searchparam = ArrayHelper::Merge(Yii::$app->request->queryParams, ['SampleSearch' => ['job_id' => $id]]);
$SampleDataProvider = $SampleSearchModel->search($searchparam);
$SampleDataProvider->pagination = false;

Gives the following error:
Creating default object from empty value

Dynagrid.php line 877: $pagination->pageSize = $this->_pageSize;

The same with sort:

Call to a member function getOrders() on boolean
Dynagrid.php line 999: $model->data = $this->gridOptions['dataProvider']->getSort()->getOrders();

add allowThemeSetting

it would be nice to deactivate this select2 out of the box

same logic as allowFilterSetting and allowSortSetting.

and / or

the ability to set the default views per widget. not only globally

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.