I am trying to come up with a way of updating multiple records of a model and as I am using YiiBooster I have seen that you can do bulk actions using the Extended Grid.
Most of the examples that I have found on the web are showing how to delete multiple records using Ajax but my requirements are slightly different. As a newbie to Yii I am struggling to work out a suitable solution to this.
Basically I have 2 models, a parent and a child with a one-to-many relation. In the child model I have a field which references which parent it belongs to using the parent ID.
In the front end of the application the user is supposed to navigate to the parent update view and then see a list of all children assigned to that parent. I have created a modal window that shows a grid list of all children with the ability to perform a bulk update action. This will then assign the parent ID to all of the children that were selected.
Can anyone help me out with this as I am unsure what I need to edit in the extended grid view and controller that will be used to update the records?
In my parent update view I pull in the index view of the children using renderPartial, as follows:
<?php $this->renderPartial('application.modules.children.views.childviews.addChild', array('dataProvider' => new CActiveDataProvider('Children'))); ?>
I then have an Extended grid in my child index view:
<?php $this->widget('bootstrap.widgets.TbExtendedGridView', array( 'type' => 'striped bordered', 'id' => 'children-grid', 'dataProvider' => $dataProvider, 'bulkActions' => array( 'actionButtons' => array( array( 'buttonType' => 'link', 'type' => 'primary', 'size' => 'small', 'label' => 'Bulk Action', 'url' => array('batchUpdate'), 'htmlOptions' => array( 'class' => 'bulk-action' ), 'id' => 'child_id', 'click' => '' ) ), 'checkBoxColumnConfig' => array( 'name' => 'child_id' ), ), 'columns' => array( 'child_id', 'child_status', 'parent_id', array( 'class' => 'bootstrap.widgets.TbButtonColumn', 'buttons' => array( 'update' => array( 'label' => '<i class="icon-user"></i> <span>View Child</span>', 'options' => array('class' => 'btn btn-small'), 'url' => 'Yii::app()->createUrl("children/update", array("id"=>$data->child_id))', ), ), ), ), )); ?>
I am guessing that I need some kind of onclick event that calls an update action in the controller and this action updates the parent_id column of all selected records to the parent id of the current parent update page?
Many thanks in advance.