12 comments on “Filtering a CGridView with an ajax-button

  1. First of all thanks for your blog. It’s very useful.

    Copying this code Firebug says “SyntaxError: unterminated string literal”

    Yii::app()->clientScript->registerScript(‘updateGridView’, ‘
    $.updateGridView = function(gridID, name, value) {
    $(“#”+gridID+” input[name="+name+"], #”+gridID+” select[name=”+name+]).val(value);
    $.fn.yiiGridView.update(gridID, {data: $.param(
    $(“#”+gridID+” .filters input, #”+gridID+” .filters select”)
    )});
    }
    ‘, CClientScript::POS_READY);

    Is there an error?

    • It worked out fine for me. I haven’t tested it with the latest version of the Yii Framework yet though but changes done in the Yii Framework should not throw this syntax error. Can you pastebin your whole view?

      • I have the same problem: SyntaxError: unterminated string literal
        I think this is maybe because of a newer jquery version. don’t you have to quote the “bracket stuff”?

        e.g:
        input[name=\”Kunde[shopId]\”]

        • Hi Kabinenkoffer,
          I believe you’re right: the value in the selector attribute should be put in quotes. I dont think it is a jQuery thing though. I believe it is a CSS thing since those are just css selectors.
          I updated the post with the fix for this.
          Kind regards,
          Fatih

    • You have to Quote the Brackets Filed, this works, please delete the other posts.

      Yii::app()->clientScript->registerScript(‘updateGridView’, ‘
      $.updateGridView = function(gridID, name, value) {
      $(“#”+gridID+” input[name=\""+name+"\"], #”+gridID+” select[name=\""+name+"\"]“).val(value);
      $.fn.yiiGridView.update(gridID, {data: $.param(
      $(“#”+gridID+” .filters input, #”+gridID+” .filters select”)
      )});
      }
      ‘, CClientScript::POS_READY);

  2. I copied the code and when I call the view I get a syntax error I do not understand:

    Parse error: syntax error, unexpected ”onclick” (T_CONSTANT_ENCAPSED_STRING), expecting ‘)’ in F:\portables\xampp1\htdocs\blog\protected\views\post\admin.php on line 21

    Attached is the view code:

    breadcrumbs=array(
    ‘Manage Posts’,
    );

    /*
    * funcio
    */
    Yii::app()->clientScript->registerScript(‘updateGridView’, ‘
    $.updateGridView = function(gridID, name, value) {
        $(“#”+gridID+” input[name="+name+"], #”+gridID+” select[name="+name+"]).val(value);
        $.fn.yiiGridView.update(gridID, {data: $.param(
            $(“#”+gridID+” .filters input, #”+gridID+” .filters select”)
        )});
    }
    ‘, CClientScript::POS_READY);
    /*
    * Botons
    */
    echo CHtml::button(‘Draft’, array(
        ’onclick’=>
            ’$.updateGridView(“post-grid”, “Post[PostStatus]“, “‘.Post::STATUS_DRAFT.’” ); ‘
    ));
    echo CHtml::button(‘Published’, array(
        ’onclick’=>
            ’$.updateGridView(“post-grid”, “Post[PostStatus]“, “‘.Post::STATUS_PUBLISHED.’”); ‘
    ));
    echo CHtml::button(‘Archived’, array(
        ’onclick’=>
            ’$.updateGridView(“post-grid”, “Post[PostStatus]“, “‘.Post::STATUS_ARCHIVED.’”); ‘
    ));

    ?>
    Manage Posts

    widget(‘zii.widgets.grid.CGridView’, array(
    ‘id’=>’post-grid’, // This line is added!
    ‘dataProvider’=>$model->search(),
    ‘filter’=>$model,
    ‘columns’=>array(
    array(
    ‘name’=>’title’,
    ‘type’=>’raw’,
    ‘value’=>’CHtml::link(CHtml::encode($data->title), $data->url)’
    ),
    array(
    ‘name’=>’status’,
    ‘value’=>’Lookup::item(“PostStatus”,$data->status)’,
    ‘filter’=>Lookup::items(‘PostStatus’),
    ),
    array(
    ‘name’=>’create_time’,
    ‘type’=>’datetime’,
    ‘filter’=>false,
    ),
    array(
    ‘class’=>’CButtonColumn’,
    ),
    ),
    )); ?>

    Can you help me?
    Thank you

  3. How to make it, if I would like a dropdown afterchange value, cgridview always update

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>