无法使用用户数据信息填充 JqGrid 页脚

发布于 2024-10-10 03:18:03 字数 2677 浏览 5 评论 0原文

我很难使用 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”信息没有被填充。有人可以帮助我吗?

谢谢 玛尔加班杜

I am having a tough time to display footer information using jqGrid. I have followed all the necessary steps to setup footer. The server request is based on some filter condition. The server returns a json with appropriate "userdata" information. Following are the JSON and javascript information.

{
    "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 Information

$("#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;
    },
  });

I tried everything listed in the jqGrid demo but for somereason, the "userdata" information is not getting populated. Can anybody help me ?

Thanks
SMargabandhu

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

放赐 2024-10-17 03:18:03

首先,您应该删除代码末尾 }); 之前的逗号。您的代码肯定不完整。例如 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' 将显示(请参阅 此处

First of all you should remove comma before }); at the end of your code. Your code is sure not full. For example url parameter is not defined so I suppose the comma come from the reduction of real code.

About your main problem. You should include jsonReader in the jqGrid definition to be able to display the JSON data which you posted. The jsonReader can be following:

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

After that the data will be displayed inclusive the 'userdata' will be displayed (see here)

紅太極 2024-10-17 03:18:03

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

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

the same name of the columns in (colModel) to return userdata, example:

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文