Yii2 Grid

Dear Kartik-V,

Thanks for your great widgets, especially you also create demo page for end users to ramp up quickly!

One question:

How to export the full grid? Or I have to remove pagination? Or have to use Yii2-excelview?

I think you will be able create more elegant methodology to do fullexport, can you help on it? Thanks.

Regards,

Scott Huang

This is a future planned extension to plugin to the grid.

Check the latest version of yii2-dynagrid extension. It allows you to personalize, save, or modify grid filters, sorts, pagesize, column order, grid theme etc.

I’m getting a error - illegal string offset ‘data-pjax’ that comes up when I attempt to implement the export configuration. Trace log shows line 565 in gridview.php function initExport()


foreach ($this->exportConfig as $format => $setting) {

            $this->exportConfig[$format]['options']['data-pjax'] = false;

        }

I’ve included Pjax::begin() etc around GridView::widget() and set pjax to true. It works fine until I set exportConfig[]

Any ideas would be greatly appreciated.

This widget has inbuilt support for PJAX. The recommended method to implement PJAX hence should be to use the internal feature - because the extension automatically initializes the other plugins like export, tableHeader etc.

Do not wrap your widget in pjax - instead set the pjax property of GridView to true. Read more about it and pjax settings in the docs.

I tried that way as well - same outcome.

Here is my code for display.


echo GridView::widget([

    	'dataProvider'=>$dataProvider,

    	'filterModel'=>$searchModel,

    	'columns' => [

    	    'account_name', 

            'first_name',

            'last_name',

            'email',

            'trade.trade',

            'position.position',

    	],

    	

    	'exportConfig'=> [

    		GridView::EXCEL=>[

    			'label' => 'Excel',

		        'icon' => 'floppy-remove',

		        'showHeader' => true,

		        'showPageSummary' => true,

		        'showFooter' => true,

		        'showCaption' => true,

		        'worksheet' => 'ExportWorksheet',

		        'filename' => 'grid-export',

		        'alertMsg' => 'The EXCEL export file will be generated for download.',

		        'cssFile' => '',

		        'options' => 'Save as Excel'],

    		],

    	'toolbar' =>  [

	        ['content'=>

	            Html::a('Create Employee', ['create'], ['class' => 'btn btn-default'])

	        ],

	        '{export}',

    	],

    	'pjax'=>true,

    	'responsive'=>true,

    	'hover'=>true,

    ]);

Sorry for wasting your time here - I must have looked at it 100 times and didn’t see the bad formatting I had on the ‘exportConfig’ options. All works great.

this part:




$timestamp = date_create_from_format("d-M-Y", $model->publish_date);

$model->publish_date = date("U", $timestamp); 



is not working anymore, how can I do this?

EDIT:




    /**

     * Creates data provider instance with search query applied

     * @return ActiveDataProvider

     */

    public function search($params)

    {

        // Transform the date to a unix timestamp for usage in the search query

        if (isset($params['NewsSearch']['date'])) {

            $origDate = $params['NewsSearch']['date'];

            $params['NewsSearch']['date'] = strtotime($params['NewsSearch']['date']);

        }


        

        $query = News::find();

        

        $query->andFilterWhere(['language' => Yii::$app->language]);

        

        $dataProvider = new ActiveDataProvider([

            'query' => $query,

            'sort' => ['defaultOrder' => ['date' => SORT_ASC]],

            'pagination' => [

                'pageSize' => 50,

            ],

        ]);


        // Join the entity model as a relation

        $query->joinWith(['translations']);

        

        // enable sorting for the related column

        $dataProvider->sort->attributes['title'] = [

            'asc' => ['title' => SORT_ASC],

            'desc' => ['title' => SORT_DESC],

        ];


        if (!($this->load($params) && $this->validate())) {

            return $dataProvider;

        }


        $query->andFilterWhere([

            'id' => $this->id,

            'date' => $this->date,

            'active' => $this->active,

            'created_at' => $this->created_at,

            'updated_at' => $this->updated_at,

        ]);


        $query->andFilterWhere(['like', 'title', $this->title]);

        

        // Format the date for display

        $this->date = $origDate;


        return $dataProvider;

    }

Спасибо. Возму на заметку.

Hello Kartik,

First of all “Happy new year 2015 !”.

I’m learning YII2 (I don’t have any previous experience in yii) and would like to continue with your gridview demo (espcially, the status “enable/disable” for all rows and for individual row…). The easist way for me to learn is to follow a working example as staring point and try to make some modifications from it.

The question: Could I get access to the .sql script fot setting the db for the demo (the book demo…)? And maybe the complete working code?

Cheers!

Viti

At first tanks for this wonderful extension.

And now the question.

I’m trying to use onDetailLoaded to run a javascript on the loaded content.

But I’ve some difficult to identify the content from the javascript.

The content is a table identified by an ID like id=‘tblSrvErg_<?=$id?>’ which use as $id the same expandRowKey used to load the remote content.

My onDetailLoaded is as follow:


'onDetailLoaded'=>'function() {'

    .'var id=<somethink that has expandRowKey value>'

    . '$(\'#tblSrvErg_\'+id).bootstrapTable();'

    . '}'

Any suggestion on how to find the id?

I just started looking at PJAX and may have misunderstood how PJAX works, but is it possible to have a Gridview in a div on a page so that when you page through the Gridview the updates stay inside that one div? When I page to the next Gridview page, the data overwrites my whole screen.

Hi,

Just wondering if it is possible to use a multi-select checkbox as a filter in one of the Griview columns? If so, could someone please give me an example of the syntax I would use for the ‘filter’ to perform this? I already have an array of key->value pairs with which to populate this.

Regards,

U4EA

With release 3.0.5 of yii2-grid, grid grouping functionalities have been added that allow to group data including master-detail nesting, adding group summaries, dynamic formatting and more. Refer group grid documentation and grid grouping demo for details.

Hi

I’m trying to use a editable column with select2, but after saving not update the grid with the description , it does with the id




		[

				'class' => 'kartik\grid\EditableColumn',

				'attribute' => 'id_provincia',

				'value' => 'provincia.descripcion',

				'format'=>'raw',

				

				'editableOptions'=>['header'=>'Provincia', 'size'=>'md',

						

						'inputType' => kartik\editable\Editable::INPUT_SELECT2,

						

						'options'=>[

								'data'=>ArrayHelper::map(

										Provincia::find()->orderBy('descripcion')->asArray()->all(),

										'id_provincia',

										'descripcion'

								),

								'pluginOptions'=>['allowClear'=>true,

								  				'placeholder'=>'Seleccione ...',

												

								],

						],

				],




What is wrong?

[edit]

in the controller, if put the value in the variable $output works!




if ($model->load($post)) {

	$model->save();


	if (isset($posted['id_provincia'])) {

	   $output =  $model->provincia->descripcion; // process as you need

	}

	$out = Json::encode(['output'=>$output, 'message'=>'']);

}

// return ajax json encoded response and exit

echo $out;

return;




I love the extension. I had an issue with my database columns, I had used the same column name in different tables and relating them gave me integrity constraint errors when I searched in the grid view filters. I renamed the offending columns in the database, and went through all of my model, controller and view code to add the new name. After doing this, the grid view filters have no effect, I can type in them but nothing happens. When I change




use kartik\grid\Gridview;



to




use yii\grid\Gridview;



every works in the filters. Any ideas as to what could be the reason?

I got it working after reinstalling from composer.

Hello Kartik!

Please help.

After update I see {toggleData} text instead button in my grid (see attachment pic):

7570

user-toggle.jpg

Best regards

Eugeny