Yii Framework Forum: Passing Form Data And Cgridview Data Simultaneously - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Passing Form Data And Cgridview Data Simultaneously Rate Topic: -----

#1 User is offline   Soumya Dev 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 20-November 11

Posted 05 December 2012 - 10:44 AM

I have a view having a single CHTML text field and a TbExtendedGridView. Selected rows from the tbExtendedGridView along with the text field data are to be submitted to the database. It is a batch addition process where each row along with the textfield data is one record.

I can get the selected rows using the js function js:{chk:$.fn.yiiGridView.getSelection('gridname')}. How can I pass the textfield data along with the selected row data in the CHTML submit button.

View File:

<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'client-account-create-form',
'enableAjaxValidation'=>false,
)); ?>

<p class="note">Fields with <span class="required">*</span> are required.</p>

<?php echo $form->errorSummary($model); ?>

<div class="row">
<?php echo $form->labelEx($model,'formname'); ?>
<?php echo $form->textField($model,'formname'); ?>
<?php echo $form->error($model,'formname'); ?>
</div>
<div class="row">
<?php
$this->widget('bootstrap.widgets.TbExtendedGridView', array(
'type'=>'striped bordered condensed',
'id'=>'grsubfielddata',
'fixedHeader' => true,
'headerOffset' => 40,

'dataProvider' => new CActiveDataProvider('Subfields',array(
'criteria'=>array(
'order'=>'tagno, slno',),
'pagination'=>array('PageSize'=>20,), )),
'enablePagination' => TRUE,

'selectableRows'=>2,
'pager' => array(
'cssFile' => false,
'header' => false,
'firstPageLabel' => 'First',
'prevPageLabel' => 'Previous',
'nextPageLabel' => 'Next',
'lastPageLabel' => 'Last',),

'template'=>"{pager}\n{items}\n{pager}",
'columns' => array(
array(
'class'=>'CCheckBoxColumn',
'id'=>'chk',
),
'tagno','fieldcode','fieldname'),


));
?>
</div>


<div class="row buttons">
<?php echo CHtml::submitButton('orgSubmit', array("data" => "js:{chk:$.fn.yiiGridView.getSelection('grsubfielddata')}")); ?>
</div>
<div>

</div>


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

</div><!-- form -->
0

#2 User is offline   alirz23 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 988
  • Joined: 08-August 12
  • Location:Durban, South Africa

Posted 05 December 2012 - 11:19 AM

There is very nice article on Batch Processing, here is the link might help you

http://www.yiiframew...in-admin-panel/
0

#3 User is offline   Soumya Dev 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 20-November 11

Posted 06 December 2012 - 09:24 AM

Thanks for the response

There were a few problems which I could solve
1) How to convert the selected rows from the gridview to string
Solution: wrote a Javascript and converted the selected rows to string and assigned it back to a hidden field.

2) Single assignment was not possible as there was a syntax error
as i was using only
$frm=>$_POST[fieldname] instead of
$frm=>$_POST[Modelname][fieldname]

Not yet solved:
I could now pass all the records from the view to the Controller (which I can print using echo) but only the last record is getting added to the database.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users