Jozsef Naghi
Jozsef Naghi

Reputation: 1095

How do I refresh grid view in Yii after AJAX using jQuery?

I'm trying to refresh the grid, but i get this error:

TypeError: $.fn.GridView is undefined

This is my js code:

$( document ).ready(function() {
        $("#username_filter").keyup(function( event ) {
            if ($(this).val().length >3){
                $.ajax({
                    url: "/common/main/filterData/",
                    type: "POST",
                    data: { username : $(this).val() },
                }).done(function() {
                    $.fn.GridView.update("#yw0");
                });
            }
        });
    });

and this is the view:

.....
$this->widget('GridView', array(
        'dataProvider' => $data,
        //'filter' => '',
        'itemsCssClass'=>'table',
        'pager' => array(
                'class'                 => 'CLinkPager',
                'prevPageLabel'         => 'Previous',
                'nextPageLabel'         => 'Next',
                'header'                => '',
                'previousPageCssClass'  => 'btn btn-info btn-sm',
                'selectedPageCssClass'  => 'btn btn-warning btn-sm',
                'internalPageCssClass'  => 'btn btn-info btn-sm',
                'firstPageCssClass'     => 'btn btn-info btn-sm',
                'nextPageCssClass'      => 'btn btn-info btn-sm',
        ),
....

Maybe it is a noob question, but where is generated the id of the grid ?

Upvotes: 0

Views: 2684

Answers (2)

alfa6661
alfa6661

Reputation: 205

it should be

$.fn.yiiGridView.update("yw0");

not $.fn.GridView

to set the id of gridview, just specify id attribute for grid view. example:

$this->widget('GridView', array(
    'id' => 'custom_id',
    .....
));

Upvotes: 0

Panoptik
Panoptik

Reputation: 1142

you can specify custom id for GridView just specify id attribute for grid view options

$this->widget('GridView', array(
    'id' => 'my_grid_id',
    'dataProvider' => $data,
    // ...
);

for manual update try this

$('#' + id).yiiGridView('update');

Upvotes: 2

Related Questions