CGridView performs sorting/filtering based on the output of 'name', and not 'value'. The 'value' is used for display purposes only. In your case, you could get your controller to perform getAttendence() for every row and then pass the output to the 'Attendence' in your dataProvider.

CGridView performs sorting/filtering based on the output of 'name', and not 'value'. The 'value' is used for display purposes only. In your case, you could get your controller to perform getAttendence() for every row and then pass the output to the 'Attendence' in your dataProvider.

I beg your pardon, But I dint get you. Can you please explain if you dont mind.

Note : I am able to get all the information into CGridView but not able to filter

CGridView's sorting and filtering are handled by its data provider. Your function 'getAttendance' does calculate the values of some CGridView's column, but it is after the data provider has done its job of providing the array of AR objects. Sorting and filtering has been completed before 'getAttendance' is called.

In order to do sorting and filtering, you have to use 'name' to tell the data provider on what data you want to do sorting or filtering. Roughly, a 'name' should either be a column name of the table, or a public variable in the model (virtual attribute that has no corresponding column).

Assuming you are using CActiveDataProvider for your grid's data provider, the first thing you have to do will be declaring a virtual attribute (e.g. 'public $attendance') in your model class. And then you have to modify your 'search' function to do the filtering and sorting using that attribute.

The following wiki is for 'Searching and Sorting' by relation, but it's quite helpful. You will understand how to use a virtual attribute to achieve your goal. http://www.yiiframew...el-in-cgridview

CGridView's sorting and filtering are handled by its data provider. Your function 'getAttendance' does calculate the values of some CGridView's column, but it is after the data provider has done its job of providing the array of AR objects. Sorting and filtering has been completed before 'getAttendance' is called.

In order to do sorting and filtering, you have to use 'name' to tell the data provider on what data you want to do sorting or filtering. Roughly, a 'name' should either be a column name of the table, or a public variable in the model (virtual attribute that has no corresponding column).

Assuming you are using CActiveDataProvider for your grid's data provider, the first thing you have to do will be declaring a virtual attribute (e.g. 'public $attendance') in your model class. And then you have to modify your 'search' function to do the filtering and sorting using that attribute.

The following wiki is for 'Searching and Sorting' by relation, but it's quite helpful. You will understand how to use a virtual attribute to achieve your goal. http://www.yiiframew...el-in-cgridview

Hi Softark,

Thanks so much for the help.

But I have no problem to workout between two models having relations. But my problem is quite different. Since I could get the values from a function (not from any related model), I am bit confused about taking care of this scenario.

But I have no problem to workout between two models having relations. But my problem is quite different. Since I could get the values from a function (not from any related model), I am bit confused about taking care of this scenario.

Well, sorry for your confusion. But, as I said, I wanted to talk about a virtual attribute, rather than a relation. And I thought the wiki mentioned will be a great help to understand the usage of a virtual attribute.

Your are displaying a calculated value in a column of a CGridView, and it has no corresponding database column. You get that value using a method called 'getAttendance'. Am I right so far? Then, when you want to sort/filter by that value, you will have to use a virtual attribute.

After all, you have to come up with some SQL which does exactly the same calculation as your getAttendance method does. As long as you want to use CActiveDataProvider, you have to do that calculation in the database level (not in AR level) in order to sort/filter by its result.

Every worker is given some tasks(assigned).
How many of tasks they have completetd is known from completed.

Now we want to know the overall efficiency of a group.Of all the tasks assigned for a particular group,
we need to know ,how many have been completed.We want to dispaly it as efficiency in Group CGrid.

Most of the time anyone who is comfortable with php rather than sql like me , things can be easily done
by CArrayDataProvider.But many may question the robustness of CArrayDataProvider, when dealing with large amount of data.

I initially planned to respond to this thread implementing CArrayDataProvider in the example I mentioned in the previous thread.

After all, you have to come up with some SQL which does exactly the same calculation as your getAttendance method does. As long as you want to use CActiveDataProvider, you have to do that calculation in the database level (not in AR level) in order to sort/filter by its result.

Thanks so much Softark.
But taking all my complex calculations to DB level is almost impossible or very hectic task.

Most of the time anyone who is comfortable with php rather than sql like me , things can be easily done
by CArrayDataProvider.But many may question the robustness of CArrayDataProvider, when dealing with large amount of data.

I initially planned to respond to this thread implementing CArrayDataProvider in the example I mentioned in the previous thread.