Pregunta

My issue is two-fold. First, I'm unable to correctly set the keyField for CArrayDataProvider, all I'm getting back is a string instead of a value. Second, I'm trying to use the keyField inside of CArrayDataProvider to set an id on the button in each row inside of CGridView. The reason I want to do this is so that I can pass the id value onward to an ajax function (if there's a better way to do this in Yii, I'm all ears). Any help would be much appreciated, thanks in advance!

I also posted this question once on Yii's forums. I normally wouldn't repost, but I have had a hard time getting answers there, as opposed to stack overflow, you guys are the best! Here's the link to my original post if anyone is interested.

Here is how I'm building the array that I'm using as my RAW data:

foreach ($items as $item) {
        $tableRow = array("id"=>$item["Id"], "Organization"=>$item["Organization"], "Roles"=>$item["Roles"]);
        $return_items[] = $tableRow;
}

Here is the CArrayDataProvider setup I'm using. I noticed that 'keyField' is not being given the id value, just the string 'id':

$dataProvider=new CArrayDataProvider($return_items, array(
        'keyField'=>'id',
        'sort'=>array(
                'attributes'=>array(
                        'Organization',
                        'Roles',
                ),
        ),
        'pagination'=>array(
                'pageSize'=>10,
        ),
));

Lastly, here is the CGridView I'm trying to setup in the view. All that appears on the button is the id tag, but no value:

$this->widget('zii.widgets.grid.CGridView', array(
        'dataProvider'=>$authItems,
        'columns'=>array(
                'Organization',
                'Roles',
                array('name'=>'', 
                          'type'=>'raw', 
                          'htmlOptions'=>array('id'=>'id'),
                          'value'=>'CHtml::button("Edit Roles", array("data-toggle"=>"modal", "data-target"=>"#roles-modal"))'), 
        ),
));
¿Fue útil?

Solución

Try passing it via CHtml::button which you have already applied. E.g.

'value'=>'CHtml::button("Edit Roles", array(
            "id"=>$data["id"],
            "data-toggle"=>"modal",
            "data-target"=>"#roles-modal"
          ))'),
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top