O
O
Oversec2016-11-03 17:59:08
Yii
Oversec, 2016-11-03 17:59:08

How to make a button when clicked on which will be filtered in the GridView?

It is necessary that the filter occurs not when the user entered the data, but when he clicked on the "Filter" button. There are a lot of filters in the table and sometimes you just don’t have time to fill them in, and the table is updated at the wrong time and you have to set the filters again. Can this be done somehow? And a reset button would be nice (I thought through js, but apparently this is not the best solution).

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Oversec, 2016-11-03
@Oversec

Found the answer to my questions. Gridview has js triggers that start sorting when the field loses blur (when the field becomes inactive). With this js code, you can prevent GV from filtering itself, and do it when you click on the button

var submit_form = false;

//Out btn for filter
$(document).on('click', '.search-submit-circle',  function(){
    //enable submit for applyFilter event
    if(submit_form === false) {
        submit_form = true;
        $("#no-js-grid").yiiGridView("applyFilter");
    }
});

//disable default submit

$(document).on('beforeFilter', "#no-js-grid" , function(event) {
    return submit_form;
});

$(document).on('afterFilter', "#no-js-grid" , function(event) {
    submit_form = false;
});

Maybe this will help someone, I sketched the code in haste, do not judge strictly

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question