russo89
(russo89)
June 21, 2019, 11:37am
1
i need implement a search by attribute “year”, but i need this in links (ex. when i click in link “2017”, $dataProvider
return only records with “year” = “2017”), in form search i have:
<?php echo Html::a('2017', '', ['class' => 'year label label-default', 'id' => '2017']) ; ?
<?php echo Html::a('2018', '', ['class' => 'year label label-default', 'id' => '2018']) ; ?>
<?php echo Html::a('2019', '', ['class' => 'year label label-default', 'id' => '2019']) ; ?>
<?php echo $form->field($model, 'minuta'); ?>
etc.......
who implement this search?
suphm
(Yusup hambali)
June 21, 2019, 11:42am
2
then you add filter in your dataprovider query
$query->andFilterWhere(['year' => $year]);
russo89
(russo89)
June 21, 2019, 11:51am
3
@suphm yes, but how i search with this link i created manually?
Easiest way is to change the link into a dropdown box
$form->field($model,'year')->dropDownList(['2012'=>2012])
Then you get all the other variables that are in the form.
The other method if you want to use links is to create a hidden field
$form->field($model,'year')->hiddenInput()
Then you js to update the variable and submit the form
<?php Html::a('2018','#',['data-val'=>2018','class'=>'mylink]) ?>
Then add the JS
$('mymodel-year').val( this.val('data-val')))
$('#myform').submit() })
russo89
(russo89)
July 8, 2019, 10:00pm
5
the only solution I found so far was yours, it’s not perfect but I could not get it any other way. thanks!