Answer the question
In order to leave comments, you need to log in
How to specify selection condition in dataProvider in Yii2?
I'm creating a gridView based on an array:
GridView::widget([
'dataProvider' => new ArrayDataProvider([
'allModels' => $user['friends']['items'],
'sort' => [
'attributes' => ['id', 'username', 'email'],
]
]),
'columns' => [
...
isset($user['friends']['items']['set_phone']);
Answer the question
In order to leave comments, you need to log in
DataProvider - not responsible for the selection condition, you need to filter the array before passing it to the DataProvider, for example using array_filter
No need to use array_filter on the DataProvider!
Open the documentation, everything is written there
nix-tips.ru/yii2-razbiraemsya-s-gridview.html
If in an example, then use searchModel!
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'rowOptions'=>function ($model, $key, $index, $grid){
$class=$index%2?'odd':'even';
return [
'key'=>$key,
'index'=>$index,
'class'=>$class
];
},
]); ?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question