ParamQuery grid support forum

General Category => Help for ParamQuery Pro => Topic started by: eroque on March 03, 2014, 09:23:21 pm

Title: Pager is not visible - PRO
Post by: eroque on March 03, 2014, 09:23:21 pm
I am migrating from Basic to PRO 2.0.4 and I have updated all the code successfully, no javascript errors. For some reason the pager is not visible any longer. What could be the reason for this behavior?
Title: Re: Pager is not visible - PRO
Post by: paramvir on March 03, 2014, 09:30:20 pm
PRO has a separate pageModel

http://paramquery.com/pro/api#option-pageModel

Please refer to the migration topic:

http://paramquery.com/pro/tutorial#topic-migration

Title: Re: Pager is not visible - PRO
Post by: eroque on March 03, 2014, 09:39:20 pm
That is what I did. Still hidden. Question: totalPages has to be set for remote paging in the getData function?


Title: Re: Pager is not visible - PRO
Post by: eroque on March 03, 2014, 09:45:14 pm
Solved!!! Thanks
Title: Re: Pager is not visible - PRO
Post by: dbadmin on June 16, 2014, 10:11:55 pm
So how do you solve this problem? I can't get pager visible with the following code:
Also, what is a correct way of throwing errors from PHP server code so that they go to "error" section?


   var dataModel = {
           location: "remote",
           sorting: "local",
        // pageModel: { type: 'remote', curPage: 1, rPP: 20, rPPOptions: [10, 30, 50, 100, 200], totalPages:1000},
           pageModel: { type: "remote", rPP: 20, strRpp: "{0}", curPage: 1 },         
           dataType: "JSON",
           method: "POST",
           recIndx: "PlantID",
           getUrl: function (ui)
              {
                 var dataModel = ui.dataModel.pageModel;
                 var filters = { "name" : $("#txName").val(),
                             "curPage": dataModel.curPage,
                             "recPerPage": dataModel.rPP,
                                 };
                   return {
                    url: "../services/Search.php",
                     data: { dataBuffer: filters }
                };
            },
           getData: function (dataJSON)
           {
               var data = dataJSON.DataArray;               
               return { curPage: dataJSON.curPage, totalRecords:1000, data: data };
           },
           error: function (err)
           {
              alert ("Error: " + err + "\n Please contact administrator with your input!");
          }          
       };
Title: Re: Pager is not visible - PRO
Post by: paramvir on June 16, 2014, 10:38:14 pm
1) pageModel is not a property of dataModel but it's a property of grid's constructor object similar to dataModel.

Example:

http://paramquery.com/pro/demos/paging

2) Throwing errors from PHP code can be displayed through error callback, it's correct the way you have done it already.
Title: Re: Pager is not visible - PRO
Post by: dbadmin on June 16, 2014, 10:42:35 pm
1. From this example I'm not sure how to capture curPage in my situation ($POST instead of $GET + filter parameters)

2. Could you give me an example of how to throw errors from PHP side? If I just remove try/catch block, it doesn't seem to work when error occurs, "alert" doesn't show up.
Title: Re: Pager is not visible - PRO
Post by: paramvir on June 17, 2014, 06:05:57 pm
1) curPage is sent to server as pq_curpage GET variable.

use dataModel.method = 'POST' if you want to handle the variables send by grid as $_POST variables.


======================================
Please create a separate post for your 2nd question.
Title: Re: Pager is not visible - PRO
Post by: dbadmin on June 17, 2014, 07:22:47 pm
So when I use method "POST", it does not seem to have this parameter that you refer GET should have. So what is the way to access it via POST?
Title: Re: Pager is not visible - PRO
Post by: paramvir on June 17, 2014, 07:38:10 pm
It's straightforward: $_POST["pq_curpage"] instead of $_GET["pq_curpage"]

If you still don't see it please post

1)  entire code for grid especially dataModel

and

2) output of print_r($_POST)
Title: Re: Pager is not visible - PRO
Post by: dbadmin on June 17, 2014, 07:55:30 pm
Yeah, my POST only contains "dataBuffer" parameter that I have added to it.

return {
                    url: "../services/Search.php",
                     data: { dataBuffer: filters }
                };

I have posted dataModel code above. Is there anything specific you're looking for?
Title: Re: Pager is not visible - PRO
Post by: paramvir on June 17, 2014, 08:06:25 pm
your dataModel posted earlier needs corrections for pageModel.

Please post the corrected dataModel and pageModel.

and you need not implement getUrl in PRO

Please refer this demo:
http://paramquery.com/pro/demos/paging
Title: Re: Pager is not visible - PRO
Post by: dbadmin on June 17, 2014, 08:15:32 pm
If I do not implement getURL, how should I pass POST parameters for filtering? Example you're referring to is for GET as far as I can see so it doesn't help me much...

Also, the reason I use pageModel in my code is that I don't see other way to pass current page in POST request.
Title: Re: Pager is not visible - PRO
Post by: dbadmin on June 17, 2014, 10:08:32 pm
So with the following code
1. Pager is not visible
2. Could you tell me how to pass current page & records per page to a service via $POST ? In $GET example you referred me to I don't seem to find where filters are being passed to a service, it seems to be a plain call without parameters.

var dataModel = {
           location: "remote",
           sorting: "local",
           pageModel: { type: "remote", rPP: 20, strRpp: "{0}", curPage: 1 },         
           dataType: "JSON",
           method: "POST",
           getUrl: function (ui)
              {
                 var filters = { "Name" : $("#txName").val(),
                             "curPage": 1,
                             "recPerPage": 20
                                 };
                   return {
                    url: "../services/Search.php",
                     data: { dataBuffer: filters }
                };
            },
           getData: function (dataJSON)
           {
               var data = dataJSON.DataArray;                 
               return { curPage: dataJSON.curPage, totalRecords:1000, data: data };         
           },
           error: function (err)
           {
              alert ("Error: " + err + "\n Please contact administrator with your input!");
          }          
       };
      
   columnModel = [     
      {title:"Name", width:150, dataType:"string", align:"right", className:'grid-col', editable: false}
       ];
   $("#grid_array").pqGrid( {
      dataModel: dataModel,
      colModel: columnModel,
      showTitle: false,
       collapsible:false,
       scrollModel:  {pace: 'fast', horizontal: false},
       numberCell: { show: false },
       flexHeight:true,
       flexWidth:true,
       sortable:true,
       columnBorders:false,
       editable: true,
       editModel: {clicksToEdit: 1, saveKey: 13},
       sortable:true
   });
Title: Re: Pager is not visible - PRO
Post by: paramvir on June 17, 2014, 10:31:31 pm
Let's take one step at a time, forget about filter parameters and anything else for a while and correct paging issue which is also the title of this topic.

your paging is not visible because as mentioned earlier, pageModel is not at right place.

pageModel is not a property of dataModel but it's a property of grid's constructor object similar to dataModel.

Example:

http://paramquery.com/pro/demos/paging
Title: Re: Pager is not visible - PRO
Post by: dbadmin on June 17, 2014, 11:03:38 pm
Oh, I got it now! It shows the pager now, thank you.

So would this be the right way to pass current page to the service VIA $POST?

                          getUrl: function (ui)
              {
                 var pageModel = ui.pageModel;
                 var filters = { "name" : $("#txName").val(),
                             "curPage": pageModel.curPage,
                             "recPerPage": pageModel.rPP,
                                 };
                   return {
                    url: "../services/Search.php",
                     data: { dataBuffer: filters }
                };
            },

I also have a question in regards of totalRecords. I prefer not to calculate total and leave it blank, but then pager misbehaves. Is there a way to handle this situation?
Title: Re: Pager is not visible - PRO
Post by: dbadmin on June 20, 2014, 03:48:17 am
Hi,

So could you tell me if this is the right way? I often get current page = 0 and it doesn't seem to be correct.
Also when I change the filtering field (Name) and search again, CurrentPage value is retrieved from a previous search, so it creates a problem when previous search had page 5, and a user was on page 5, but new search only has 3 pages -- a user gets an empty resultset.

Thanks!
Title: Re: Pager is not visible - PRO
Post by: paramvir on June 20, 2014, 10:05:04 pm
That's the right way to send parameters to the server. However the end result in the grid i.e., remote paging and remote filtering is little bit dependent upon on your javascript and more dependent upon how you handle the parameters on the server side. If you write incorrect PHP code, you would get incorrect result in the grid.

The benefit of using paramquery filter method and following the demos is that it takes care of

sending filter parameters on its own
protects against SQL injection attacks.
you can use the already written filterHelper method in PHP.

http://paramquery.com/pro/demos/filter_header