Issue
i wanna change filter of gridview in yii2 .i want to use drop down list and check box to add filter instead of filter text box.
1)undefine Laptop model error 2)in my code drop down list worked but showing empty list without text.(i think i wrong some thing) .help me to solve it.
here is my code
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
//'id',
[
'attribute'=>'id',
'value'=>'id',
//'filter'=>array("1"=>"open","2"=>"in progress","3"=>"closed")
'filter' => Html::activeDropDownList($searchModel, 'id', ArrayHelper::map(Laptop::find()->asArray()->all(), 'id', 'laptop'),['class'=>'form-control','prompt' => 'Select Category']),
],
'network',
'technology',
'sup_id',
'speaker',
'size',
[
'class' => 'yii\grid\ActionColumn',
'template' => '{myButton}' , // the default buttons + your custom button
'buttons' => [
'myButton' => function($url, $model, $key) { // render your custom button
return Html::a('تایید');
}
]
],
// [
// 'class' => DataColumn::className(), // this line is optional
/* 'attribute' => 'name',
'format' => 'text',
'label' => 'Name',
],*/
// 'optical_drive',
//'webcam',
// 'touchpad',
// 'card_reader',
// 'ethernet',
// 'vga',
// 'hdmi',
// 'usb3_ports',
// 'usb2_ports',
// 'usb_type_c',
// 'thunderbolt_ports',
// 'serial_ports',
['class' => 'yii\grid\ActionColumn'],
],
'layout' => '{summary}{items}{pager}',
]); ?>
in below part what should i change to solve this problem?
<?
[
'attribute'=>'id',
'value'=>'id',
//'filter'=>array("1"=>"open","2"=>"in progress","3"=>"closed")
'filter' => Html::activeDropDownList($searchModel, 'id', ArrayHelper::map(Laptop::find()->asArray()->all(), 'id', 'laptop'),['class'=>'form-control','prompt' => 'Select Category']),
],
?>
thanks :))
Solution
try add the realted use clause in your view
eg if you have all the models in common\models
use common\models\LapTop;
or
use your_app_name\models\LapTop;
assign the proper value to your_app_name
or for basic template try
use app\models\LapTop;
and for filter try using only
'filter'=>ArrayHelper::map(LapTop::find()->asArray()->all(), 'id', 'laptop'),
Answered By - ScaisEdge
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.