How to set key value in CGrideView when grid is po

2019-07-26 18:01发布

问题:

In Yii CGridView, when we select any row from grid by using:

'selectionChanged' => "function(id){ $.fn.yiiGridView.getSelection(id) }",

it gives proper key value of the record (when the grid is populated by table)


But, when I populate Grid with data of 3 tables as a View. The key value returns undefined.

I have id as field, and I want it as key value in that particular view. So, I can get Id of particular row to proceed further.

p.s.:
All the 3 tables have their own Primary Key.

回答1:

Have you looked into these options?

KeyAttribute (CActiveDataProvider)

KeyField (CArrayDataProvider)

They are what is used to generate that id in a gridview