Cgridview - Get Header, Post Filter

Hi all,

I am running into issues getting a POST-based form used to provide filter/sesarch conditions with a Gridview with column sorting capabilities.

I have it working if the form is set for GET - pagination, sort, and filter - however in doing so, the URL becomes bulky and unreadable, along with the fact I’d like to hide the search query string from the user where possible (and what happens if it exceeds maximum length of url?).

In 1.1.14 there is a new var called ajaxType which I have tried setting to POST however this does not resolve the problem.

I guess I could separate the controller actions and give it a dedicated ajaxUrl and come up with some means for passing filter information between controller methods however I feel this is a non-intuitive and possibly dirty workaround.

I have spent the last week or so trying to dig through this however I have had no resolve. The column headers are still GET based ajax links, and clicking them in a POST-based form causes a loss of filter.

Any help, suggestions or hints as to where to look would be greatly appreciated!

Here is some code snippets which illustrate my setup:


function actionAdvSearch() {


        $model = new Post('search');

        $model->Author = new Author('search');


        if (isset($_POST['Post'])) {

            $model->attributes = $_POST['Post'];



        $this->render('advsearch', array('model' => $model));


View: /post/advSearch/

<?php $form = $this->beginWidget('CActiveForm', array(


    'method' => 'post'

)); ?>

	<div class="row-fluid">

            <div class="span4">

		<?php echo $form->label($model, 'id'); ?>


            <div class="span8">

		<?php echo $form->textField($model, 'id', array('maxlength' => 45)); ?>



	<div class="row-fluid">

            <div class="span4">

		<?php echo $form->label($model->author, 'name'); ?>


            <div class="span8">

		<?php echo $form->textField($model->author, 'name', array('maxlength' => 80)); ?>



	<div class="row-fluid">

            <?php echo CHtml::submitButton(); ?>



            $this->widget('zii.widgets.grid.CGridView', array(

                'ajaxType' => 'post',

                'type' => 'condensed bordered striped',

                'columns' => $columns,

                'dataProvider' => $model->search(),



<?php $this->endWidget(); ?>

Anyone have any ideas or suggestions?

Bump for a reply?

Last time? Guess everyone is clueless? I still have not been able to trace through it. Any help?

Hi MattyD,

I also come across this problem. I am planning to make CGridView able to add a new row via filter rows. My client wants to add a new row but wanted to check filtered tables first to avoid duplication. I know that we can check duplicate through model validation. But, he wants to see some inputted value before add a new one.

ajaxType POST makes me confident that I can fulfill the requirement. Until I found out that my CGridView failed on the CSRF.

Have you progress on this?


I would also be interested in finding a fix for this. Getting ‘CSRF token could not be found’ error when sorting/filtering in CGridview and when ajaxType is set to POST.