5

As you can see in this image

enter image description here

I have 13 records on my DB but the pager says it has only 1 page (with 10 rows), which is not correct.

Relevant part of the code from my .js

function cria(){
$("#grid").jqGrid({
    datatype: 'json',
    url: 'json.jsp',
    jsonReader: {repeatitems: false},
    pager: '#paginado',
    rowNum: 10,
    rowList: [10,20,30],
    emptyrecords: "Não há registros.",
    recordtext: "Registros {0} - {1} de {2}",
    pgtext: "Página {0} de {1}",
    colNames:['Código','Descrição'],
    colModel:[
        {name:'codigo', width:80, sorttype:"int", sortable: true, editable: false},
        {name:'descricao', width:120, sortable: true, editable: true, editrules:{required:true}}
    ],
    viewrecords: true,
    editurl:"dadosGrid.jsp?edit=true",
    caption: "Grupos",
    hiddengrid: true
});             

$("#grid").jqGrid('navGrid','#paginado',{},
    {edit:true,url:"Adm?aux=edit",closeAfterEdit:true,reloadAfterSubmit:true},
    {add:true,url:"Adm?aux=add",closeAfterAdd:true,reloadAfterSubmit:true},             
    {del:false},
    {search:true},
    {refresh:true});    
};

Relevant part of the code from my .jsp

String json = "[";
for (UserAux user : users ){
    json += "{";
    json += "\"codigo\":\""+user.getCod()+"\",";
    json += "\"descricao\":\""+user.getDescricao()+"\",";
    json += "},";
}
json = json.substring(0,json.length()-1);   
json += "]";                        
out.println(json);  
%>
lucasdc
  • 1,032
  • 2
  • 20
  • 42

1 Answers1

10

Default options of jqGrid means that you implements server side paging. If you want to returns all data at once from the server (which would be good choice if you have 13 records) you should just add loadonce: true option.

Additionally I would recommend you to add gridview: true, autoencode: true and height: "auto" option to your jqGrid. Moreover you should remove edit:true, del:false, search:true and refresh:true which you use inside of options navGrid because you use there on the wrong place. If you want to specify the options you should specify properties of the second parameter (which is {} in your code).

Oleg
  • 220,925
  • 34
  • 403
  • 798
  • I tried to add loadonce:true, gridview:true and I also moved my navGrid options to inside {}. None of the options (add,edit,del) are working now, looks like it cannot fined their url's.. – lucasdc Nov 28 '13 at 15:34
  • @lucasdc: The usage of `loadonce: true` only should solve your problem already. What you means under "looks like it cannot fined their url"? If you use wrong URLs then no data should be displayed in the grid. The text of your question I interpret so that the *first* page will be displayed correctly and you have only the problem with paging. So please confirm that the first page of the grid will be correctly displayed. – Oleg Nov 28 '13 at 16:17
  • My first page is displayed kinda correctly. As I showed in my image, I got 13 records (it will be much more in future like 10k+), the first page shows 10 records, but the grid says there is only 1 page of records, but actually there should be 2 pages (10 + 3). The arrows are not clickable, but if I select to show 20 rows, the other 3 (that should be on the 2nd page) are displayed on the grid. What I mean with "looks like it cannot find their url" is that I think that the way you showed me to pass parameters (like this): {edit:true, del:false, search:true} doesn't work – lucasdc Nov 28 '13 at 16:32
  • @lucasdc: Could you append the text of your question with exact response from the server with JSON data? In the case I can reproduce your test. **I am sure that the problem should be solved if you add `loadonce: true` to the list of jqGrid options.** Probably you placed the option on the wrong place? – Oleg Nov 28 '13 at 16:39
  • Alright, since you were so secure for what you were saying I made a thorough look on my code and I found that I've written "loadOnce" instead of "loadonce". The pagination worked. If you could take a look on this question I'd appreciate. http://stackoverflow.com/questions/20265384/jqgrid-password-confirmation. Thank you very much! – lucasdc Nov 28 '13 at 16:50
  • @Oleg yeah **loadonce: true ** doesn't work for reloading grid with new data from server whereas changing it to false create problem in pagination. I think your updated fork would be the solution to this, right? will surely give it a try – Adil Apr 20 '16 at 06:30
  • 1
    @Bhaiya: The usage of `loadonce: true` is recommended way if you need to display not so large number of items in the grid (<1000 or <10000). You can use the latest (4.13.2) version of free jqGrid from CDN for example (see [the wiki article](https://github.com/free-jqgrid/jqGrid/wiki/Access-free-jqGrid-from-different-CDNs)) or download it. I implemented many new features and the usage of `fromServer: true` in reloadGrid and the usage of `reloadGridOptions: { fromServer: true }` option in `navGrid` (see UPDATED 2 part of [the answer](http://stackoverflow.com/a/3772720/315935)) – Oleg Apr 20 '16 at 06:52