Gridview filter as you type

Hi

I’m applying a filter as you type solution to a Gridview in Yii2. It works fine but for some reason it is submitting the form twice each time (although the first one gets aborted if you type quickly). Any ideas what is causing it to submit twice or is there a better way to do this?




$this->registerJs("

$('body').on('keyup.yiiGridView', '#user-grid .filters input', function(){

	$('#user-grid').yiiGridView('applyFilter');

});

",View::POS_END);






Pjax::begin(['id' => 'datatable-user', 'timeout' => false, 'enablePushState' => false]);

echo GridView::widget([

'id' => 'user-grid',

'dataProvider' => $dataProviderUser,

'filterModel' => $searchModel,

	 'filterSelector' => 'select[name="per-page"]',

'tableOptions' =>['class' => 'table table-hover dataTables-default margin bottom dataTable no-footer dtr-inline'],

'layout' => "{items}\n{pager}",

'columns' => [

	[

		'attribute' => 'short',

		'format' => 'url',

		'value' => function ($model) {                      

				return $model->short;

		},

	],

	'full',

	'clicks' => [

		'label'=>'Clicks',

		'filter'=>false,

		'value'=>function ($model) {                      

				return $model->clicks;

		},

	],

	[

		'attribute' => 'timestamp',

		'format' => 'raw',

		'filter'=>false,

		'value' => function ($model) {                      

				if(date('Ymd') == date('Ymd', $model->timestamp)){

					$day = 'Today '.date("g:ia - d.m.Y",$model->timestamp);	

				}

				else if(date('Ymd', time() - 60 * 60 * 24) == date('Ymd', $model->timestamp)){

					$day = 'Yesterday '.date("g:ia - d.m.Y",$model->timestamp);	

				}

				else {

					$day = date("l g:ia - d.m.Y",$model->timestamp);	

				}

				return $day;

		},

	],

	[

	'class' => 'yii\grid\ActionColumn',

	'header'=>'Copy',

	'template' => '{copy}',

	'buttons' => [

			'copy' => function ($url, $model) {

				return Html::button($content='<i class="fa fa-files-o"></i>', [

							'title' => Yii::t('app', 'Copy'),

							'class' => 'copyb tn btn-white btn-xs pull-right',

							'id' => $model->short,

				]);

			}

		],

	],

	[

	'class' => 'yii\grid\ActionColumn',

	'header'=>'Delete',

	'template' => '{delete}',

	'buttons' => [

			'delete' => function ($url, $model) {

				return Html::a('<button class="btn btn-white btn-xs pull-right"><i class="fa fa-trash"></i></button>', $url, [

							'title' => \Yii::t('app', 'Delete'),

							'data-confirm' => \Yii::t('yii', 'Are you sure to delete this link?'),

	

				]);

			}

		],

	],

],

]);

Pjax::end();



I have the same problem, if you found solution please notify me with your code.