无法使用userdata信息填充JqGrid页脚

时间:2010-12-28 20:06:33

标签: json jqgrid user-data

我很难用jqGrid显示页脚信息。我已经按照所有必要的步骤来设置页脚。服务器请求基于某些过滤条件。服务器返回带有适当“userdata”信息的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演示中列出的所有内容,但是对于某些原因,“userdata”信息没有填充。有人能帮助我吗?

由于 SMargabandhu

2 个答案:

答案 0 :(得分:0)

首先,您应该在代码末尾的});之前删除逗号。您的代码肯定不完整。例如,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

答案 1 :(得分:0)

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

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