【问题标题】:Unable to populate JqGrid footer with userdata information无法使用用户数据信息填充 JqGrid 页脚
【发布时间】:2010-12-28 20:06:33
【问题描述】:

我很难使用 jqGrid 显示页脚信息。我已按照所有必要的步骤设置页脚。服务器请求基于某些过滤条件。服务器返回一个带有适当“用户数据”信息的 json。以下是 JSON 和 javascript 信息。

{
    "timeatt": [
        {
            "empnum" : "12345",
            "name" : "ABCDEFG",
            "shift" : "1",
            "postdate" : "12/27/10",
            "regular" : "40",
            "ot" : "8",
            "dbltime" : "0",
            "holiday" : "0",
            "vacation" : "0",
            "payrate" : "0" 
        },
        {
            "empnum" : "67890",
            "name" : "HIJKLMN",
            "shift" : "1",
            "postdate" : "12/27/10",
            "regular" : "32",
            "ot" : "0",
            "dbltime" : "0",
            "holiday" : "0",
            "vacation" : "8",
            "payrate" : "0" 
        } 
    ],
    "userdata": {
        "name": "Totals",
        "regular": "72",
        "ot": "8",
        "dbltime": "0",
        "vacation": "8",
        "holiday": "0"
    },
    "totalrecords" : "2" 
}

jQGrid 信息

$("#empinfo").jqGrid({
    datatype:'json',
    colNames:['Clock#','Name','PostDate','Shift','Regular','Over Time','Dbl Time',
              'Vacation','Holiday'],
    colModel:[{name:'empnum', index:'empNum', width:60},
              {name:'name', index:'name', width:200},
              {name:'postdate', index:'postdate', width:60,editable:false,
               hidden:true,editrules:{edithidden:false}},
              {name:'shift', index:'shift', width:60,editable:true,edittype:'text'},
              {name:'regular', index:'regular', width:70,editable:true,
               edittype:'text',align:"right", formatter: 'number'},
              {name:'ot', index:'ot', width:70,editable:true,edittype:'text',
               align:"right", formatter: 'number'},
              {name:'dbltime', index:'dltime', width:70,editable:true,
               edittype:'text',align:"right", formatter: 'number'},
              {name:'vacation', index:'vacation', width:70,editable:true,
               edittype:'text',align:"right", formatter: 'number'},
              {name:'holiday', index:'holiday', width:70,editable:true,
               edittype:'text',align:"right", formatter: 'number'}],
    scroll:1,
    scrollRows:true,
    height:300,
    editurl:'clientArray',
    footerrow:true,
    userDataOnFooter:true,
    altRows:true,
    onSelectRow: function(rowNum){
        if (rowNum && rowNum != lastSel) {
            $("#empinfo").saveRow(lastSel);
        }
        $("#empinfo").editRow(rowNum,true);
        lastSel = rowNum;
    },
  });

我尝试了 jqGrid 演示中列出的所有内容,但由于某种原因,“用户数据”信息没有得到填充。有人可以帮帮我吗?

谢谢 SMargabandhu

【问题讨论】:

    标签: json jqgrid user-data


    【解决方案1】:

    首先,您应该删除代码末尾}); 之前的逗号。您的代码肯定不完整。比如url这个参数没有定义,所以我猜逗号来自于真实代码的缩减。

    关于您的主要问题。您应该在 jqGrid 定义中包含 jsonReader 以便能够显示您发布的 JSON 数据。 jsonReader 可以如下:

    jsonReader: {
        repeatitems: false,
        root:'timeatt',
        page: function (obj) { return 1; },
        total: function (obj) { return 1; },
        records: function (obj) { return obj.length; }
    }
    

    之后将显示数据(包括'userdata')(请参阅here

    【讨论】:

    • 谢谢奥列格。你的解决方案奏效了。我不确定 jsonReader。我只是一个初学者,我正在尝试每个属性。但是非常感谢您指出我的错误。
    • 您好 Oleg,当我指定 URL 属性时,您的解决方案有效。但在我的情况下,URL 是空的,因为我有一个过滤条件,并且基于此我执行一个函数,该函数进行服务器调用以获取所需的 JSON 数据。填充jqGrid(addRowData)后是否可以设置页脚行。
    • @Shanker:尝试使用footerData方法:$("list").jqGrid("footerData","set",myUserData,true);
    【解决方案2】:

    (colModel)中同名的列返回userdata,例如:

    userdata = new { hours= lista.Sum(x => x.Horas).ToString(), function= "Total HH:" }

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-24
      • 2017-02-04
      相关资源
      最近更新 更多