Yii Framework Forum: Yii2 Grid - Yii Framework Forum

Jump to content

  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

Yii2 Grid GridView enhancements and utilities for Yii Framework 2.0. Rate Topic: ***** 1 Votes

#21 User is offline   Scott_Huang 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 54
  • Joined: 18-July 13
  • Location:Xiamen, China

Posted 24 October 2014 - 03:51 AM

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
0

#22 User is offline   Kartik V 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 651
  • Joined: 29-August 12

Posted 25 October 2014 - 02:47 AM

View PostScott_Huang, on 24 October 2014 - 03:51 AM, said:

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.
0

#23 User is offline   Kartik V 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 651
  • Joined: 29-August 12

Posted 25 October 2014 - 02:50 AM

View PostErik_r, on 06 April 2014 - 03:16 PM, said:

2) Filtering is a good possibility but it can't be stored. My idea is to have an enrichment which could be added to your grid. This extension should a selection box and a button. If you push the button you get a dialog in which you can add a filter name and you can reorder the columns including hiding. If you store this name then the current filter settings, sort order, column order will be stored under the grid name, filter name and user in the database. One name should be marked as default if the grid is rendered first time.

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.
0

#24 User is offline   BuildMT 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 29-October 14

Posted 29 October 2014 - 01:52 PM

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.
0

#25 User is offline   Kartik V 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 651
  • Joined: 29-August 12

Posted 29 October 2014 - 02:04 PM

View PostBuildMT, on 29 October 2014 - 01:52 PM, said:

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.
0

#26 User is offline   BuildMT 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 29-October 14

Posted 29 October 2014 - 03:05 PM

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

0

#27 User is offline   BuildMT 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 29-October 14

Posted 29 October 2014 - 04:06 PM

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.
0

#28 User is offline   Hashie 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 39
  • Joined: 20-February 14

Posted 30 October 2014 - 05:18 AM

View PostKartik V, on 18 May 2014 - 09:28 AM, said:

The GridView::FILTER_DATE will render the kartik\widgets\DatePicker widget. Refer docs for DatePicker widget on options supported.

You need to pass the format options for displaying the date in DatePicker. Use the filterWidgetOptions property:
'filterWidgetOptions' => [
   'pluginOptions'=>['format' => 'dd-mm-yyyy']
]

Also, you need to convert back the date time to a user friendly format for display in your grid column. So your complete column looks like this
[
    'attribute'=>'publish_date',
    'value'=>function ($model, $index, $widget) {
        return date("d-M-Y", $model->publish_date);
    },
    'filterType'=>GridView::FILTER_DATE,
    'filterWidgetOptions' => [
        'pluginOptions'=>['format' => 'dd-mm-yyyy']
    ]
],

Then in your model->search function you need to convert this date format back to unix timestamp before filter query is executed. Something like
$timestamp = date_create_from_format("d-M-Y", $model->publish_date);
$model->publish_date = date("U", $timestamp); 



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;
    }

0

#29 User is offline   keygenqt 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 12-November 14

Posted 12 November 2014 - 08:04 PM

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

#30 User is offline   Vitiok 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 01-January 15

Posted 01 January 2015 - 06:48 PM

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
0

#31 User is offline   Roberto Braga 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 190
  • Joined: 18-February 13
  • Location:Roma, Italy

Posted 12 January 2015 - 08:57 AM

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?
0

#32 User is offline   compugator 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 62
  • Joined: 01-May 11

Posted 21 April 2015 - 04:43 PM

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.
0

#33 User is offline   U4EA 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 300
  • Joined: 04-November 12

Posted 30 June 2015 - 11:42 AM

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
0

#34 User is offline   Kartik V 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 651
  • Joined: 29-August 12

Posted 07 July 2015 - 02:16 PM

View PostPractice_OPL, on 17 July 2014 - 08:35 AM, said:

I think that your GridView should be default Yii2 GridView, but it could be better :rolleyes:
I don't know if there is a way to group columns in your GridView, so I've added it to Yii2 by myself, but my code isn't nice and I'm sure you can make it better.
I know that there is some 'group columns' that generate HTML tag 'colgroup' [in 2amigos editable grid extension as I remember], but with this I can only edit CSS of 'group'.

I think that many users need real 'group columns' - possiblity to put few model attributes in one column.


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.
0

#35 User is offline   gallego123 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 536
  • Joined: 11-August 09
  • Location:Argentina

Posted 12 November 2015 - 10:59 AM

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;


Attached File(s)


KISS - Keep It Simple Stupid
ASAP-As Soon As Possible
http://www.yiiframew...oc/cookbook/71/
0

#36 User is offline   newbiedo 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 72
  • Joined: 28-June 12

Posted 04 August 2017 - 03:49 PM

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?
0

#37 User is offline   newbiedo 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 72
  • Joined: 28-June 12

Posted 04 August 2017 - 05:08 PM

I got it working after reinstalling from composer.
0

Share this topic:


  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users