Business model:
One invoice can have can have multiple status (Draft, in progress, send, deleted).
In CGridView I want display invoices with last status
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'carriage-grid',
'dataProvider'=>$model->search(array(
'completed'=>true,
'pagination'=>true,
)),
'filter'=>$model,
'columns'=> [
array(
'name'=>'InvoiceName',
'type'=>'raw',
'value'=>$model->InvoiceName,
),
array(
'name' => 'InvoiceStatus',
'value' => $model->InvoiceStatus->Name,
),
]
)); ?>
In invoice model I have declared relation:
'status'=>array(self::HAS_MANY, 'InvoiceStatus', 'invoice_id'),
In CGridView data displayed is correct, but when I try to order by InvoiceStatus->name
What I get:
(BY ASC)
- Invoice name + first status
- Invoice name 2 + first status
(BY DESC)
- Invoice name + last status
- Invoice name 2 + last status
What I expect to get:
(BY ASC)
- Invoice name + A status
- Invoice name 2 + B status
(BY DESC)
- Invoice name 2 + B status
- Invoice name 1 + A status
That mean, that I want order all record not only status, and always display last status