简体   繁体   中英

How to call applyFilter function on GridView

Instead of using Pjax, which is giving me some problems, i would like to know how to apply the filter in a Yii2 GridView using javascript.

In the yii.gridView.js (loaded on yii2 every time you use the GridView widget) there are this lines inside var methods:

 applyFilter: function () {
        var $grid = $(this);
        var settings = gridData[$grid.attr('id')].settings;
        var data = {};
        $.each($(settings.filterSelector).serializeArray(), function () {
            if (!(this.name in data)) {
                data[this.name] = [];
            }
            data[this.name].push(this.value);

}); ...

How do i call this function using javascript inside my page?

Try

grid.yiiGridView("applyFilter");

where grid is a GridView (ie element of .grid-view class).

$('.grid-view').yiiGridView("applyFilter");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM