Skip to content

Instantly share code, notes, and snippets.

@Bizunow
Last active December 6, 2017 08:10
Show Gist options
  • Save Bizunow/211cdd0d39fab4a678c2f0f844740c73 to your computer and use it in GitHub Desktop.
Save Bizunow/211cdd0d39fab4a678c2f0f844740c73 to your computer and use it in GitHub Desktop.
[Yii ajax CGridView] #php, #yii
<?php
/**
* @var $previousExportsDataProvider CArrayDataProvider
*/
$columns = array(
[
'header'=>CHtml::encode('Name'),
'name' => 'name',
],
[
'header'=>CHtml::encode('Date'),
'name'=>'date',
]
);
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'ajax-grid',
'ajaxUrl' => 'instagram/renderAjaxGrid',
'dataProvider'=>$dataProvider,
'columns'=>$columns,
'pager' => [
'firstPageLabel' => false,
'lastPageLabel' => false,
]
));
<?php
class InstagramController extends Controller
{
public function actionRenderAjaxGrid()
{
$data = []; // Array with your data
$this->render('_audience_exports', [
'dataProvider' => new CArrayDataProvider($data)
]);
}
}
<?php
$this->renderPartial('_audience_exports', [
'previousExportsDataProvider' => new CArrayDataProvider([])
])
?>
<button class="btn-refresh">Refresh</button>
<script>
$('.btn-refresh').click(function() {
$.fn.yiiGridView.update('ajax-grid');
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment