Yii2 Gridview pagination losing POST data.

Hey there,

I’ve implemented a form filter to filter a GridView dataprovider, that some time can have a lot of fields. Bearing this in mind, GET method is not supported to me because I can receive something like from Apache/Nginx:

So, when I click in any pagination link, I lost the POST data. How to keep my filter without change my HTTP method?!

I saw some approaches using Pjax, something like this:

Pjax::begin(['clientOptions' => ['method' => 'POST']]);

It didn’t work, though.

Since I am not using a regular filter (it is a dynamic filter that I’ve created), I do not use the $model->load method. I used to use somethiing like the following:

$attributes = Yii::$app->request->post('attribute');

$type = Yii::$app->request->post('type');

$filter = Yii::$app->request->post('filter');

Also, you can see in the attached images the ajax sent using PJAX, it doens’t have a POST data.

Thanks in advance

You can add js code

$js = <<< JS
$(document).on('ready pjax:success', function() {
        function updateURLParameter(url, param, paramVal)
        var TheAnchor = null;
        var newAdditionalURL = “”;
        var tempArray = url.split("?");
        var baseURL = tempArray[0];
        var additionalURL = tempArray[1];
        var temp ="";                       
        if (additionalURL)                                    
            var tmpAnchor = additionalURL.split("#");         
            var TheParams = tmpAnchor[0];                     
            TheAnchor = tmpAnchor[1];                         
                additionalURL = TheParams;                    
            tempArray = additionalURL.split("&");             
            for (var i=0; i<tempArray.length; i++)            
                if(tempArray[i].split('=')[0] != param)       
                    newAdditionalURL += temp + tempArray[i];  
                    temp = "&";                               
            var tmpAnchor = baseURL.split("#");               
            var TheParams = tmpAnchor[0];                     
            TheAnchor  = tmpAnchor[1];                        
                baseURL = TheParams;     
            paramVal += "#" + TheAnchor;                                       
        var rows_txt = temp + "" + param + "=" + paramVal;                     
        return baseURL + "?" + newAdditionalURL + rows_txt;                    

    $('.pagination li a').click(function(event){
            var page = $(this).data('page') + 1;
            var href = updateURLParameter(this.href, 'page', page); 
            $('#searchForm').prop('action', href);