Vasilis Lourdas
Vasilis Lourdas

Reputation: 1179

How to refresh CGridView control using values from other controls

I have set up a CGridView widget in my application. It displays a list of user accounts. I also have two other drop down lists that basically filter out the users. My problem is that I cannot use the values from the drop down lists to filter out the users. What I actually need is to refresh the list of user accounts based on the selected values from the drop down lists.

How am I supposed to do that with Javascript?

Upvotes: 1

Views: 3489

Answers (1)

bool.dev
bool.dev

Reputation: 17478

Yes you use Javascript to do this. CGridView's jquery.yiigridview.js has $('#id-of-grid').yiiGridView('update', options) function which can be used for such things:

function(){// in your function
    $('#id-of-grid').yiiGridView('update', {data: {value_of_list: $(this).val()}});
}

This will call the url that renders this view with a parameter value_of_list with the value selected in the drop down.

Edit:

The $('#id-of-grid').yiiGridView('update', options) signature indicates that you can specify which grid to update, and also the specific options to be sent. In the above example i have sent only data, i could have also specified which url to send the data to using url option. The full list of options can be seen in the link i have specified above.

Upvotes: 3

Related Questions