Could someone explain me why CSqlDataProvider forces me to use a keyField? It’s ‘id’ by default, and it must be specified, otherwise loading of the data fails.
And what I also don’t understand, is why all these keys are listed after the table (CGridView) in a hidden <div>.
What am I supposed to do if I don’t need keys whatsoever?
CGridView can display any tabular data, right? It may be fetched from any conceivable source, eg. a complex join or a hierarchical query. In many cases it’s simply not possible to have a unique key on the result set.
What do you think of making the keyField-related functionality optional?
yktoo, tables w/o any keys are quite rare. TBH, I haven’t ever seen one in production. However, you might be able to just fetch all rows from your table and feed them to your CGridView via the CArrayDataProvider. It’s a bit of a hack, but it might be worth the try.
Hm, okay… Yii’s very own CDbLogRoute does indeed use a primary key. If you do not feel like adding an extra key field to your table (or add all existing fields to a primary key), you might want to extend the CGridView class (in particular the CGridView.renderItems() method).