json - jqGrid - 分页无法正常工作

标签 json jqgrid pagination pager

正如你在这张图片中看到的

enter image description here

我的数据库上有 13 条记录,但寻呼机说它只有 1 页(有 10 行),这是不正确的。

来自我的 .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});    
};

来自我的 .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);  
%>

最佳答案

jqGrid 的默认选项意味着你实现了 服务器端分页 .如果您想一次从服务器返回所有数据(如果您有 13 条记录,这将是一个不错的选择),您只需添加 loadonce: true选项。

此外,我建议您添加 gridview: true , autoencode: trueheight: "auto" jqGrid 的选项。此外,您应该删除 edit:true , del:false , search:truerefresh:true您在选项中使用的选项 navGrid因为你在错误的地方使用那里。如果你想指定选项,你应该指定第二个参数的属性(在你的代码中是 {})。

关于json - jqGrid - 分页无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20267596/

相关文章:

php - JQGrid,如何将 JSON 字符串发送到 PHP 进行处理并发送到数据库?

javascript - 带有导航栏/寻呼机的 jqGrid 具有绑定(bind)到编辑按钮的自定义功能

php - 如何在 Symfony 2 中有效地使用 paginate with doctrine?

php 在同一行回显页码

php - 为什么 next_post_link() 不能与 WP_Query 一起使用?

javascript - 如何转义字符串中的多个层次引号(HTML)

json - 如何让nodejs返回一个名副其实的json对象给postman?

jquery-ui - 在列上使用格式化程序时,JQGrid 过滤器工具栏不过滤行

javascript - 无法从 json 文件 AngularJS 获取正确的数据

arrays - PostgreSQL:计算嵌套在 JSONB 列中的唯一数组值的出现次数?