Yii2:如何在不使用模型的情况下修改 GridView 的数据列



我在控制器中创建了一个带有productprice列的SqlDataProvider。

然后,我在视图中使用 GridView 来显示两列,但我需要将$价格连接起来,以便我可以显示例如75 美元

我知道如何使用模型来做到这一点,但在这种情况下,我没有模型。

<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
'product',
[
'attribute'  => 'price',
'value' => function($model) {
return '$ ' . $model->price; // I don't have a model so it doesn't work here.
}
],
],
]) ?>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
'product',
[
'attribute' => 'price',
'value' => function ($model) {
return '$ ' . $model['price'];
}
],
],
]) ?>

相关内容

最新更新