Is it possible to modify SQL used in CGridView?

I’m really sorry, cause I know that I’ve been asking this question in middle of some other discussion, but simply can’t find it! :confused:

I’m listing items in my CGridView using as data provider CActiveDataProvider, which criteria method points to and CDbCriteria instance with some conditions.

Is there any way to modify SQL query that is being used in this process?

Thanks to mdomba and guide I know that I can use CDbCriteria.condition to see / modify SQL part after WHERE clause. But is it possible to be able to modify whole SQL being used in this situation? I.e. not only WHERE part, but whole SQL, including SELECT part, ORDER BY with respecting selected sorting method, LIMIT part respecting pagination being used in CGridView etc.?

Or the only way to achieve this is to replace CActiveDataProvider with CSqlDataProvider and write whole SQL from scratch with modification I intend to do?

Look at the other properties/methods of the CDbCriteria

‘select’=>‘field1, field2, field3,…etc’,

‘order’=>‘field, field2’,



I think you misunderstood me.

I know these properties and I’m using them. And I can see / modify WHERE part of generated SQL with CDbCriteria.condition. But I don’t know if I can / how to access whole SQL that is later being genterated inside CActiveDataProvider / CGridView, which includes also pagination and sorting user selected in CGridView.