jqGrid - Pagination not working properly
Asked Answered
O

1

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);  
%>
Outcast answered 28/11, 2013 at 13:34 Comment(0)
B
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).

Bordereau answered 28/11, 2013 at 15:8 Comment(7)
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..Outcast
@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.Bordereau
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 workOutcast
@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?Bordereau
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. #20265884. Thank you very much!Outcast
@Bordereau 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 tryDogoodism
@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) 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)Bordereau

© 2022 - 2024 — McMap. All rights reserved.