How to keep variable value use throughout all records in clistview

Hello,

i have used clistview.

my requirement is to print total on each record.

like following in randerPartial _view.php,

1’st record total= total+$data->amount(value 100); total=100;

2’nd record total= total+$data->amount(value 100); total=200;

2’rd record total= total+$data->amount(value 100); total=300;

and so on…

but i cant get last updated value of total variable.

it overwrite value in each record. how to keep variable updated and used.

Hi

A gridview works with many models and I suppose ClistView does the same.

First your have the main $model - which is used to call the search() function to create the dataprovider.

The dataprovider also contains many models - one for each gridview row. They are called $data in each row.

Since each row in the gridview uses its own model (called $data) it does not help to store your total in $data, because the next row will not use the same $data.

If you want to store your total in such a way that ALL rows can access it, then you have to store it in the main $model.

Have a look at this wiki.

HI,

I am not sure about the following but may help you.

In While loop we use an increment variable suppose i and do i++ at the end.

Same way you may follow by having a variable and use it inside your _view of listing to add up the total, like you variable is $totalofAll= 0 in code calling the listview than inside listview you will do $totalofAll+$data->amount.

Let me know it helps or you need further.

Hello,

Here i find my solution.




class AbcController extends Controller

{

    public $total=0;

}



and then use it in your renderPartial _view.php like




$this->total += $data->amount(value 100);



Hope it helps you. see link

link