PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, March 8, 2022

[FIXED] Yii CGridView renders a new page instead of AJAX

 March 08, 2022     ajax, php, yii     No comments   

Issue

In the index page of my site I have floating div-block with CGridView inside.

I need to use sort, filter, paging etc. options, but only via updating this only div and not refreshing the whole page.

Data rendering as it should, i'm stuck only with updating grid contents - all <a>'s have href, that sending user to specified view.

Here's the view for grid: (it's the only content of my views.users.usersGrid.php)

$this->widget('zii.widgets.grid.CGridView', array(
    'dataProvider' => $model->search(),
    'filter' => $model,
    'ajaxUrl' => 'modules/subcntrl/usersGrid',
    'ajaxUpdate' => 'users-grid',
    'columns' => array(
        array(
            'name' => 'name',
            'type' => 'raw',
            'value' => 'CHtml::encode($data->name)'
        ),
        array(
            'class'=>'CButtonColumn',
        ),
    ),
));

It's called from views.users.users.php: <?php $this->actionUsersGrid(); ?>

Controller:

public function actionUsers() {
    $this->renderPartial('users');
}

public function actionUsersGrid() {
    if(!Yii::app()->request->isAjaxRequest) die('Url should be requested via ajax only');
    $model = new Users();
    $this->renderPartial('usersGrid',array(
        'model' => $model,
    ));
}

Would appreciate any help


Solution

please use the third and fouth parameter in renderPartial method like this,

$this->renderPartial('users',array(),false,true);

it will solve your problem (setting the processOutput=true ) in the fourth parameter



Answered By - Sudhanshu Saxena
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing