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 -->
Page 1 of 1
Passing Form Data And Cgridview Data Simultaneously
#2
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/
http://www.yiiframew...in-admin-panel/
#3
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.
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.
Share this topic:
Page 1 of 1