I'm working with Yii 2, and it's gridview to show information.
我正在使用Yii 2,它是gridview来显示信息。
Now, my problem is that whenever a user scans two identical serial numbers and/or mac addresses, it should highlight the row (change color to red), and show some error sign or whatever.
现在,我的问题是,每当用户扫描两个相同的序列号和/或mac地址时,它应该突出显示该行(将颜色更改为红色),并显示一些错误符号或其他。
Screenshot:
What I want it to look like:
我希望它看起来像:
I'm new to Yii2 and don't exactly know how they do it with the gridview. I've been researching on this specific problem but couldn't find anything.
我是Yii2的新手,并不清楚他们是如何使用gridview做的。我一直在研究这个具体问题,但找不到任何东西。
Code for Gridview (Nothing special)
Gridview代码(没什么特别的)
<?= GridView::widget([
'id' => 'scan-batch-grid',
'dataProvider' => $dataProvider,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
['class' => 'yii\grid\CheckboxColumn'],
[
'attribute' => 'product_ID',
'value' => 'product.name'
],
'SN',
'MAC',
[
'class' => 'yii\grid\ActionColumn',
'urlCreator' => function ($action, $model, $key, $index) {
return Url::to(['scan-batch/view', 'id' => $key, 'scan' => $model->scan_batch_ID]);
},
'buttons' => [
'update' => function ($url, $model, $key) {
return '';
},
'delete' => function ($url, $model, $key) {
return '';
},
],
],
],
]); ?>
Could anyone help me? A link or even a slightly relevant Q/A would be appreciated!
谁能帮助我?我们将非常感谢链接或者甚至是相关的Q / A!
EDIT
I only want to know how to change the color of only one row, I can do the checks myself! :)
我只想知道如何改变一行的颜色,我可以自己做检查! :)
2 个解决方案
#1
17
Got it!
Yii2 : Adding Classes to Rows in the GridView (YouTube)
Yii2:在GridView(YouTube)中向行添加类
Yii2 Gridview row by row css expression
Yii2 Gridview逐行css表达式
Simply add rowOptions to your gridview.
只需将rowOptions添加到gridview即可。
<?= GridView::widget([
'id' => 'scan-batch-grid',
'dataProvider' => $dataProvider,
'rowOptions'=>function($model){
if($a == $b){
return ['class' => 'danger'];
}
},
#2
3
Thanks for posting your answer Paramone. Worked great.
感谢您发布您的答案Paramone。工作得很好。
Here is my implementation:
这是我的实施:
<?= GridView::widget([
'dataProvider' => $dataProvider,
'rowOptions' => function ($model) {
if ($model->name == 'test') {
return ['class' => 'info'];
}
},
#1
17
Got it!
Yii2 : Adding Classes to Rows in the GridView (YouTube)
Yii2:在GridView(YouTube)中向行添加类
Yii2 Gridview row by row css expression
Yii2 Gridview逐行css表达式
Simply add rowOptions to your gridview.
只需将rowOptions添加到gridview即可。
<?= GridView::widget([
'id' => 'scan-batch-grid',
'dataProvider' => $dataProvider,
'rowOptions'=>function($model){
if($a == $b){
return ['class' => 'danger'];
}
},
#2
3
Thanks for posting your answer Paramone. Worked great.
感谢您发布您的答案Paramone。工作得很好。
Here is my implementation:
这是我的实施:
<?= GridView::widget([
'dataProvider' => $dataProvider,
'rowOptions' => function ($model) {
if ($model->name == 'test') {
return ['class' => 'info'];
}
},