Hello, I’m newbie. Need your some help …
I am working with a project on yii and i want to provide a grid system to add records on my client demand.
User will be able to add bulk of data at the same time and in this last row will contains [+] button at the end. When user will click on this button a new row will be append.
With the help of different post on this forum i have successfully performed the add data function. But now i m facing the issue in update data.
at the time of update form will be load with the all records. Eg: MS Excel
he can modify any cell value then just clicked on the update changes and all values should be save
Please help me to fix this issue
This is my create Action
public function actionCreate(){
$model = new ProSize;
if(isset($_POST['ProSize'])){
$formData = $_POST['ProSize'];
$modelData = array();
foreach($formData as $rowKey => $rowData){
$i = 0;
foreach($rowData as $rowColKey => $rowColData){
$modelData[$i++][$rowKey] = $rowColData;
}
}
foreach($modelData as $m){
$mModel = new ProSize;
$mModel->attributes = $m;
$mModel->save();
}
}
$this->render('create',array(
'model'=>$model,
));
}
This is my _form.php
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'pro-size-form',
'enableAjaxValidation'=>false,
)); ?>
<?php echo $form->errorSummary($model); ?>
<div id="gridFormSubList">
<div class="tbl unbreak gridform" style="width:100%;">
<div class="cell">
<?php echo $form->textField($model,'PRODUCT_ID[]',array('maxlength'=>10)); ?>
</div>
<div class="cell">
<?php echo $form->textField($model,'SIZE_DETAIL[]',array('maxlength'=>150)); ?>
</div>
<div class="cell">
<?php echo $form->textField($model,'SIZE_CODE[]',array('maxlength'=>15)); ?>
</div>
<div class="cell">
<?php echo $form->textField($model,'REF_CODE_1[]',array('maxlength'=>12)); ?>
</div>
<div class="cell">
<?php echo $form->textField($model,'REF_CODE_2[]',array('maxlength'=>12)); ?>
</div>
<div class="cell">
<?php echo $form->textField($model,'REF_CODE_3[]',array('maxlength'=>12)); ?>
</div>
<div class="cell">
<?php echo $form->textField($model,'REF_CODE_4[]',array('maxlength'=>12)); ?>
</div>
<div class="cell">
<?php echo $form->textField($model,'REF_CODE_5[]',array('maxlength'=>12)); ?>
</div>
<div class="cell">
<?php echo $form->textField($model,'REF_CODE_6[]',array('maxlength'=>12)); ?>
</div>
<div class="cell">
<?php echo $form->textField($model,'REF_CODE_7[]',array('maxlength'=>12)); ?>
</div>
<div class="cell">
<?php echo $form->textField($model,'REF_CODE_8[]',array('maxlength'=>12)); ?>
</div>
<div class="cell" style="width:40px">
<input type="button" value="+" onclick="cloneRow($(this))" class="cloneGridRowBtn" style="width:30px" />
</div>
</div>
</div>
<script type="text/javascript">
function cloneRow(obj){
newRow = obj.parent().parent().clone();
newRow.find('input[type="text"]').attr('value','');
$('#gridFormSubList').append(newRow);
$('#gridFormSubList').find('.cloneGridRowBtn').css('display','none');
$('#gridFormSubList>div:last-child').find('.cloneGridRowBtn').css('display','block');
$('#gridFormSubList>div:last-child .cell:first-child input[type="text"]').focus();
}
</script>
<div class="row buttons">
<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
</div>
<?php $this->endWidget(); ?>
</div>
Now problem is this. How update action will work…??
How i can load multiple records in _form to provide the user to update functionality…
Thanks in advance