Hi,
I have list of articles with category column, on the top of it the grid there is select drop list that has all the categories, the user can select one row or multiple rows, then he select the wanted categories to update the selected articles category via ajax. All works fine, but after a success ajax call the grid table disappear, and only the top select box remain.
Any idea how to update one row, or to refresh the whole grid after successful Ajax call ?
The view
Yii::app()->clientScript->registerScript('categories', "
$('#categories').change(function() {
var row = $(this).parent().parent();
var xdata = $('input', row)//.serialize();
var id= $('#rssqueue-grid').yiiGridView('getChecked','selectedIds');
var newCat = $( this ).val();
console.log(newCat)
$.fn.yiiGridView.update('rssqueue-grid', {
type: 'POST',
//url: 'updateCategory',
data: {newCat,id},
//data: xdata,
success:function(data) {
$.fn.yiiGridView.update('rssqueue-grid',{data: $(this).serialize()});
//$('#AjFlash').html(data).fadeIn().animate({opacity: 1.0}, 3000).fadeOut('slow');
console.log('Success: '+data)
//console.dir(xdata);
//console.log(JSON.stringify(row, null, 4))
}
})
});
", CClientScript::POS_READY);
/* Categories select box */
$categories = CHtml::listData(Category::model()->findAll(), 'id','name');
echo CHtml::dropDownList('categories', $models->state_id, $categories, array('empty' => '(Select a state'));
$this->widget('bootstrap.widgets.TbExtendedGridView',array(
'id'=>'rssqueue-grid',
//'type' => 'condensed striped',
'fixedHeader' => true,
'selectableRows'=>2,
'headerOffset' => 40,
//'responsiveTable' => true,
'dataProvider'=>$model->search(),
'filter'=>$model,
'ajaxUpdate'=>true,
'afterAjaxUpdate'=>'function(id, data){
console.log("update is done")
$.fn.yiiGridView.update("rssqueue-grid");
}',
'ajaxUrl'=> Yii::app()->createUrl('rssqueue/updateCategory'),//'updateCategory',
'summaryText'=>'<b>Total: {count}</b>',
'template' => "{summary}\n{pager}\n{items}\n{pager}",
'bulkActions' => array(
'actionButtons' => array(
array(
'buttonType' => 'button',
'context' => 'primary',
'size' => 'small',
'label' => 'Testing Primary Bulk Actions',
'click' => 'js:function(values){console.log("values");}',
'url' => array('batchDelete'),
'id' => 'changeCategory',
)
),
// if grid doesn't have a checkbox column type, it will attach
// one and this configuration will be part of it
'checkBoxColumnConfig' => array(
'name' => 'id'
),
),
'pager'=>array(
'class'=>'ext.myPager',
'header'=>'<div class="pagination-centered clearfix">',
'htmlOptions'=>array('class'=>'pagination'),
'lastPageLabel'=>'',
'firstPageLabel'=>'',
'nextPageCssClass'=>'arrow',
'prevPageLabel'=>'»',
'nextPageLabel'=>'«',
'footer'=>'</div>',
//'PageSize '=>Yii::app()->params["defaultPageSize"],
),
'columns'=>array(
array(
'name' => 'selectedIds',
'id' => 'selectedIds',
'value' => '$data->id',
'class' => 'CCheckBoxColumn',
'selectableRows' => '2',
),
array(
'name'=>'id',
'htmlOptions'=>array('width'=>'60'),
'headerHtmlOptions'=>array('width'=>'40'),
),
array(
'name'=>'title',
'type'=>'html',
'value' => 'CHtml::link(CString::cut(10,$data->title),$data->RssLink)',
'htmlOptions'=>array('width'=>'420'),
'headerHtmlOptions'=>array('width'=>'120'),
),
array (
'name'=>'Rss_id',
'value'=>'$data->source->RssName',
'htmlOptions'=>array('width'=>'120'),
'headerHtmlOptions'=>array('width'=>'120')
),
array(
'name'=>'cid',
'value'=>'$data->category->name',
'filter' => CHtml::listData(Category::model()->findAll(), 'id','name'),
'htmlOptions'=>array('width'=>'120'),
'headerHtmlOptions'=>array('width'=>'120')
),
array(
'name' => 'Date',
'type' => 'datetime',
'htmlOptions'=>array('width'=>'120', 'style'=>'font-size:12px;'),
'headerHtmlOptions'=>array('width'=>'120'),
'filter'=>'',
),
),
));
[size="6"]Thanks in advance [/size]