【问题标题】:jqgrid duplicate rows in spite of having uique idjqgrid 重复行,尽管有唯一的 id
【发布时间】:2013-05-12 19:55:19
【问题描述】:

问题: 我从服务器发送 10 行(假设 jqgrid 每次请求 10 行)。

第一次提取:发送/显示 10 行(id:1 到 10)查看网格中 25 个中的 1-10 个

第二次获取:发送/显示 10 行(id:11 到 20)在网格中查看 11 - 20 个,共 25 个

第三次获取:发送 5 行/显示 10 行(id:21 到 25,然后是 21 到 25)在网格中查看 21 - 30 个,共 25 个

属性集(来自业务层):page=3,records=25

javascript:

<script type="text/javascript">
$(function() {
    $("#list").jqGrid({
        url : contextPath + "/getEntities",
        datatype : 'json',
        mtype : 'GET',
        jsonReader : {
            root : "response",
            page : "page",
            total : "total",
            records : "records",
            repeatitems : false

        },
        colNames : [ 'Inv No', 'Date', 'Amount', 'Tax', 'Total', 'Notes' ],
        colModel : [ {
            name : 'invid',
            width : 55,
            index : 'invid',
            sortable : true,
            sorttype : 'text',
            key : true
        }, {
            name : 'invdate',
            index : 'invdate',
            width : 90,
            sorttype : 'date',
            sortable : true
        }, {
            name : 'amount',
            index : 'amount',
            width : 80,
            align : 'right'
        }, {
            name : 'tax',
            index : 'tax',
            width : 80,
            align : 'right'
        }, {
            name : 'total',
            index : 'total',
            width : 80,
            align : 'right'
        }, {
            name : 'note',
            index : 'note',
            width : 150,
            sortable : false
        } ],
        pager : '#pager',
        rowNum : 10,
        rowList : [ 10, 20, 30 ],
        sortname : 'invid',
        sortorder : 'desc',
        viewrecords : true,
        gridview : true,
        caption : 'My first grid'
    });
});

下面是json数据:

{"total":3,
"response":[
{"total":"490","amount":"500","invdate":"12-12-12","invid":"21","tax":"10","note":"OK"},
{"total":"490","amount":"500","invdate":"12-12-12","invid":"22","tax":"10","note":"OK"},
  {"total":"490","amount":"500","invdate":"12-12-12","invid":"23","tax":"10","note":"OK"},
{"total":"490","amount":"500","invdate":"12-12-12","invid":"24","tax":"10","note":"OK"},
  {"total":"490","amount":"500","invdate":"12-12-12","invid":"25","tax":"10","note":"OK"}],
"page":3,
"records":25}

注意:invid 在所有行中都包含唯一值,因此在 colModel 中定义为键。同样对于第 3 次提取,我会请求 10 行但从服务器接收 5 行。网格不应该显示 5 并且不重复行,因为我设置了重复项:false。我还设置了records=25,同时将json数据发回显示。这不意味着总记录 = 25。为什么它显示 25 的 21-30 视图?

请帮忙...

【问题讨论】:

    标签: javascript json jquery jqgrid


    【解决方案1】:

    抱歉,我无法重现您描述的问题。 The demo 显示正确结果

    【讨论】:

    • 感谢您尝试复制该问题。我是否必须在某处设置我要发送以供网格使用的行数?
    • @PravatPanda:不客气!如果您的意思是文本“查看 21-25 of 25”,那么您应该在 JSON 响应中正确设置 recordstotalpage。你已经正确地做到了。 The following part of jqGrid code 显示文本。仅当您返回错误的 page 属性值时,文本才可能是 View 21 - 30 of 25(也请参见 here)。您发布的数据是正确的。
    • 再次感谢...从服务器第 2 页开始发送时数据重复,这是错误。现在我能够实现服务器端分页,它真的很棒,代码行数很少。我能否请您提供一个简单的客户端排序和显示网格全屏的解决方案(考虑调整屏幕大小),它现在非常小,几乎占据了 25% 的屏幕。
    • @PravatPanda:不客气!我个人更喜欢使用height: "auto" 并允许用户从值列表rowList 中选择最喜欢的rowNum。我将选择与其他首选项一起保存在localStorage 中(请参阅here)。
    猜你喜欢
    • 2016-04-15
    • 2014-07-17
    • 1970-01-01
    • 2017-12-19
    • 2011-11-09
    • 1970-01-01
    • 2019-11-13
    • 1970-01-01
    • 2012-06-23
    相关资源
    最近更新 更多