Problem with filtering Gridview within yii\jui\Dialog

Hello,

so basically what i’m trying to do here is to create some kind of List Of Value Dialog for the foreign key attribute, which contains Gridview from the related Model. so user can choose the value and it can be copied to the input form instead of letting them manually insert it to the input field. by doing this we can minimize human error in the Input form (i set the textfield to readonly, so users can only changes the value by choose it from the Dialog).

i have managed to create a dialog (using yii\jui\dialog), create gridview within it. the only problem i encounter is the gridview within the JUI dialog can’t be filtered properly. actually the filter is going well, but every time i tried to filter the grid, the dialog also will be closed.

i also have tried to use Pjax by encapsulate the gridview within Pjax::begin(); and Pjax::end(); the modal dialog will not be closed this time but the problem is… i can only filter the grid 1 times. once the grid is filtered, it is not triggering another filter.

here is some example in my’_form’views : (i am using a button “Cari” to show the pop up dialog)




<?php $form = ActiveForm::begin(); ?>


    <?= $form->field($model, 'judul')->textInput(['maxlength' => true]) ?>


    <?= $form->field($model, 'isi')->textarea(['rows' => 6]) ?>


    <?= $form->field($model, 'kategori_id', [

    	'addon' => 	['append' => 

    					['content'=> 

    						Html::button('x', ['class'=>'btn btn-default','name' => 'del_kat', 'id' => 'del_kat', 'onclick' => '$("#kat_id").val("");'])  . PHP_EOL .

    						Html::button('Cari', ['class'=>'btn btn-primary','id' => 'modal_kat', 'onclick' => '$("#kategori_dialog").dialog("open"); return false;' ]),

    						

    						'asButton' => true

    					]

    				]

	])->textInput(['id'=> 'kat_id', 'readonly' => true]) ?>



here is my GridView Code (i am using another button to pass the "kategori_id" value from Gridview within Dialog to the original "_form" view):




$kategoriGrid = GridView::widget([

        'dataProvider' => $kategoriModel->search(Yii::$app->request->queryParams),

        'filterModel' => $kategoriModel,

        'columns' => [

            //['class' => 'yii\grid\SerialColumn'],


            'kategori_id',

            'nama',

             [

	            'label' => 'test',

	            'format' => 'raw',

	            'value' => function ($data) {

	                

	                return Html::button('+', ['class'=>'btn btn-default','id' => 'modal_kat', 'onclick' => '$("#kategori_dialog").dialog("close"); $("#kat_id").val("'.$data->kategori_id.'");' ]);

	            },

	        ],


            

        ],


    ]);



and here my Dialog Code :




Dialog::begin([

	'id' => 'kategori_dialog',

    'clientOptions' => [

        'modal' => true,

        'autoOpen'=>false,

         'title'=>'List Kategori',

         'width'=>'auto',

    ],

    

]);


Pjax::begin(['id' => 'kategori-pjax', 'enablePushState'=>false]);

echo $kategoriGrid;

Pjax::end(); 


Dialog::end();



as you guys can see, i tried to use Pjax but somehow i couldn’t get it work as expected. it can only filter once and cannot trigger any filter action after that.

any thoughts on this?

P.S : this is my attempt to upgrade my old Yii 1.1 application to Yii 2.0. in Yii 1.1 i simply used zii.widgets.jui.CJuiDialog as a dialog wrapper and create Gridview widget within it. the filter works fine back then. so i wonder if i am missing something here in Yii 2.0.

Many Thanks,

Rangga

so i found the solutions to my problem. i just using Kartik’s Gridview (use kartik\grid\GridView) which has built it Pjax implementation. and somehow it works.

kudos to Krajee / Kartik.