- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是新来的,无法发表评论 here
当我尝试在页脚中获取总和时遇到问题。
我在 Controller 中的代码:
$searchModel = new ReceiptsSearch();
$sum = new ReceiptsSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
'sum'=>$sum,
]);
public function search($params)
{
$query = Receipts::find();
$sum = $query->sum('price');
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$this->load($params);
if (!$this->validate()) {
return $dataProvider;
}
$query->joinWith('patient');
$query->andFilterWhere([
'id' => $this->id,
'price' => $this->price,
'reg_date' => $this->reg_date,
]);
$query->andFilterWhere(['like','patient.patient_name',$this->patient_id]);
return $dataProvider;$sum;
}
<?= GridView::widget([
'dataProvider' => $dataProvider,$sum,
'filterModel' => $searchModel,
'showFooter' => true,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
[
'attribute'=>'patient_id',
'value'=>'patient.patient_name'
],
'price',
],
[
'attribute' => 'sum',
'footer' => 'sum',
],
['class' => 'yii\grid\ActionColumn'],
],
]);
?>
Setting unknown property: yii\grid\GridView::0
最佳答案
Controller
$searchModel = new ReceiptsSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
public function search($params)
{
$query = Receipts::find()->joinWith('patient');
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$this->load($params);
if (!$this->validate()) {
return $dataProvider;
}
$query->andFilterWhere([
'id' => $this->id,
'price' => $this->price,
'reg_date' => $this->reg_date,
]);
$query->andFilterWhere(['like','patient.patient_name',$this->patient_id]);
return $dataProvider;
}
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'showFooter' => true,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
[
'attribute' => 'patient_id',
'value' => 'patient.patient_name'
],
[
'attribute' => 'price',
'footer' => Receipts::getTotal($dataProvider->models, 'price'),
],
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
public static function getTotal($provider, $fieldName)
{
$total = 0;
foreach ($provider as $item) {
$total += $item[$fieldName];
}
return $total;
}
关于gridview - Yii2 : Get Sum In footer of gridview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40629352/
鉴于下面的基本 HTML 结构(我无法更改),我知道我可以使用此 CSS 扩展主要内容 div: html, body { height: 100%; } body { display: fl
这应该类似于 iOS tableview 页脚,也可以在各种网站中看到(粘性页脚)。 我想实现以下目标: A 是具有可变行数的 RecyclerView。 当 A 小于屏幕(或父级)尺寸时,B(页脚)
我有一个 Bootstrap 面板,底部有两个按钮: {{ Form::open( array('route' => array('dogs.edit', $dog->id)
我是一名优秀的程序员,十分优秀!