save data from textfield with cgridview

Hello.

I’m using cgridview and put textfield into few collumns so that i’ll able to edit the data on that collumns (directly on that page).

the question is: how to build a button to save all data from that textfield?


$this->widget('zii.widgets.grid.CGridView', array(

        'id' => 'score-grid',

        'dataProvider' => $model->search(),

        'filter' => $model,

        'columns' => array(

                'id',

                array(

                                'name'=>'subject_id',

                                'value'=>'GxHtml::valueEx($data->subject)',

                                'filter'=>GxHtml::listDataEx(Subject::model()->findAllAttributes(null, true)),

                                ),

                                array(

                        'name' => 'score_id',

                        'filter' => CHtml::listData(BookScore::model()->findAll(), 'id', 'student_id'), 

                        'value' => 'GxHtml::valueEx($data->rapor)',

                ),

                array(

                        'name'=>'Score1',

                        'value'=> 'Chtml::textField(\'TestScore1\', $data->Score1, array(\'width\'=>20,\'maxlength\'=>3))',

                        'type'=>'raw',

                        'htmlOptions'=>array('width'=>'20px'),

                        ),

                array(

                        'name'=>'Score2',

                        'value'=> 'Chtml::textField(\'TestScore2\', $data->Score2, array(\'width\'=>20,\'maxlength\'=>3))',

                        'type'=>'raw',

                        'htmlOptions'=>array('width'=>'20px'),

                        ),

                array(

                        'name'=>'Score3',

                        'value'=> 'Chtml::textField(\'TestScore3\', $data->Score3, array(\'width\'=>20,\'maxlength\'=>3))',

                        'type'=>'raw',

                        'htmlOptions'=>array('width'=>'20px'),

                        ),

                array(

                        'class' => 'CButtonColumn',

                        'template'=>'{save}{delete}',

    'buttons'=>array

    (

        'save' => array

        (

            'label'=>'save',

//i'd like to do save data from here



Thx

For this, you need to create the form using the data of CGridView and save the data using Ajax.

Could you give me some example? :)

Thx

I will give you a pseudo code for it.

Create a Widget of a widget as

Form Widgate // Start

CGridView widgate

// Close it

And in the form elements, create each filed as required as




<?php $form=$this->beginWidget('CActiveForm', array(

	'id'=>'login-form',

	'enableAjaxValidation'=>true,

)); ?>




<?php echo $form->textField($data,'username'); ?> 

// Place your CGridView data here


<?php $this->endWidget(); ?>

Check this similar topic - http://www.yiiframework.com/forum/index.php?/topic/14111-

Thx all, problem solved… :D

Happy Christmas