Dear Friend
There are sometimes we have to update the gridView based on form fields placed outside the grid.
I have done it by updating the grid by single value.
These are couple of examples.
1.I have 2 tables.
Brand(id,name) and
Item(id,name,b_id).
Through b_id, a brand has
MANY items.
Through external dropDrownList,I am updating the grid.
$('#subForm form').submit(function(){
$.fn.yiiGridView.update('item-grid', {
data:{'Item[b_id]':$('#subForm #Item_b_id').val()}
});
return false;
});
");
In this example, I have three tables:
user,customer,UserCustomer.
user has MANY_MANY relation through userCustomer.
I am getting ids from
usergrid and
customergrid by
getChecked method.
I creating UserCustomer from these values by AJAX. After successful creation,
I am updating the
userCustomer grid for the particular user.
2.
Yii::app()->clientScript->registerScript('assignCustomer','
$("body").on("click","#butt",function(){
$.ajax({
type:"POST",
url:"'.Yii::app()->createUrl('userCustomer/create').'",
data:$(".wide form").serialize(),
success:function(data){
$("#user-customer-grid").yiiGridView("update",{
data:{"UserCustomer[user_id]":$("#user").val()}});
}
});
return false;
});
');
Note: In first example $(this)means whole
form.
In second example $(this) means
click button.
To avoid that confusion, I am fetching the values by their ids.
Regards.