【发布时间】:2015-07-15 09:10:48
【问题描述】:
我必须检查其他表格中的产品数量并在当前网格视图中显示。所以我在模型中创建了一个函数来获取该列的计数。
但我的问题是如何在网格视图中对自定义列 (checked_kpl) 进行排序。
这是我的代码。
型号
public function search() {
$criteria = new CDbCriteria;
$criteria->compare('id', $this->id, true);
$criteria->compare('purchase_order_id', $this->purchase_order_id);
$criteria->compare('product_id', $this->product_id);
$criteria->compare('unit_price', $this->unit_price, true);
$criteria->compare('qty', $this->qty, true);
$criteria->compare('cost_price', $this->cost_price, true);
$criteria->compare('customs_percent', $this->customs_percent, true);
$criteria->compare('discount_percent', $this->discount_percent, true);
$criteria->compare('notes', $this->notes, true);
$criteria->compare('created_at', $this->created_at, true);
$criteria->compare('updated_at', $this->updated_at, true);
return new CActiveDataProvider($this, array(
'criteria' => $criteria,
));
}
}
public function getCheckedKpl() {
$checked_kpl = 0;
if (!empty($this->purchaseOrderArrivals)) {
foreach ($this->purchaseOrderArrivals as $eachArrival) {
$checked_kpl += $eachArrival->qty;
}
}
return $checked_kpl;
}
注意: - purchaseOrderArrivals 是另一种模型。我已经与这个模型建立了关系。 - getCheckedKpl 函数让我计算产品数量。
VIEW - 在视图中,我将此代码放在 gridview 小部件中以显示列。
array(
'name' => 'checked_kpl',
'value' => '$data->getCheckedKpl()',
'type' => 'raw',
'class' => 'DataColumn'
),
任何帮助将不胜感激。谢谢。
【问题讨论】: