Problems In Sorting Relational Columns

Hai All,Gone through the tutorial for searching/sorting in relational attributes.but i dint found how to sort if we use customized function to display data where we have three modules.module1 has the attribute clientname , module2 has the relation BELONGS TO- ‘client’ to the model1,and i have one more module named module3 with relation ‘detail’ BELONGS TO module2.

In module2 i have a customized function,

                     public function getClientname(){


	            return $this->client->name;


	         }

For displaying client details in gridview of module3 i am using $data->RelName->clientname where RelName is ‘detail’ and clientname is name of the customised function that returns the name of the client of model1.That works fine,

But i have a problem while sorting and searching.can any one help how can i sort by using CSORT with this customized function.