Problem With Sorting

Hi

i have 2 models User and Calls with User has many Calls relationship.now i need to show data in cGridview,data is showing correctly but i need to apply sorting.in cGridview i had an attribute ‘Called?’ Which have value ‘yes’ or ‘no’ which represent if Calls Model Have a record corresponding to User.i am using a function in controller to show ‘yes’ or ‘no’ in cGridview based on Calls model have an entry or not. How can i implemet sorting on this field?thanks in advance

Pass the return value of that function to the dataProvider used for the GridView. For more, refer to this link: http://www.yiiframework.com/forum/index.php/topic/39410-how-to-make-custom-column-of-cgridview-filterable/page__p__189159__fromsearch__1#entry189159

thanks BCR for help

but can you tell me how can i "Pass the return value of that function to the dataProvider used for the GridView" as suggested by you

my guess from ex. is that it need to be define with following statement

$criteria->compare(‘filed’,‘value’,true);

can you explain a bit more?thanks

I’ll need to have a look at your view & controller for that.

this is the view

array(

            'header'=>'Called?',


            'name'=>'Called',


            'type'=>'raw',


            'value'=>array($this, 'ccaleadstatus'),


             'htmlOptions'=>array(


                    'class'=> 'adminleadId',


            )


            ) ,

this is in controller

public function ccaleadstatus($data) {

    $return = isset($data->wish_ccacall["id"])?"Yes":"No";


    return $return;


}

anybody?

Hi

Please can anybody tell me if i use a function to show value of a colomn in gridview and this function show value from database but if the value is not available in database then it show ‘no’ custom text.can anybody tell be how can i sort this colomn.thanks in advance.can somebody show this by example?thanks in advance

Hi prashant.tyagi,

This is a kind of STAT relation. It’s relatively easy to display it in the grid.

But in order to filter/sort by this kind of calculated data, you need to do some trick. In short, we can make use of sub query in SELECT clause and in WHERE clause when we define the criteria.

Please take a look at this wiki article:

http://www.yiiframework.com/wiki/319/searching-and-sorting-by-count-of-related-items-in-cgridview