jqgrid 未定义整数?寻呼机未加载 [英] jqgrid undefined integer? pager not loading

查看:15
本文介绍了jqgrid 未定义整数?寻呼机未加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

IM 在 mvc4 上使用 jqgrids,我需要获取一个简单的列表并使用 Ajax 显示它.

IM using jqgrids on mvc4, I need to get a simple list and display it using Ajax.

当我加载页面然后网格启动 Ajax 调用时,我在网格上只有 2 列、user_id 和 name.

When I load the page then grid starts an Ajax call, I have only 2 columns on grid, user_id and name.

加载 Json 后,我在 Google chrome 上收到下一个错误:

When the Json is loaded I get the next error on Google chrome:

未捕获的排字机:无法读取未定义的属性整数"

在 firefox 中,firebug:

and in firefox, firebug:

类型错误:b.jgrid.formatter 未定义

在 jquery.jqGrid.src.js:122 上

on jquery.jqGrid.src.js:122

网格显示一个未定义"的味精,同样,当前的寻呼机控件没有加载,但数据是

And the grid shows an "undefined" msg, also, the current pageer control isnt loading, but the data is

 <table id="GridUsuarios"></table>
    <div id="PagerUsuarios"></div>


  <script type="text/javascript"> 
        $(document).ready(function() {
            jQuery("#GridUsuarios").jqGrid({
                url: '@Url.Action("UsuariosGridData","Usuarios")',
                datatype: "json",
                myType: 'GET',
                contentType: "application/json; charset-utf-8",                
                colNames: ['Usuario', 'Nombre'],
                colModel: [
                    { name: 'user_id', index: 'user_id', width: 90},
                    { name: 'nombre', index: 'nombre', width: 200}
                ],
                pager: '#PagerUsuarios',
                rowNum: 10,
                rowList: [10, 20, 30],
                viewrecords: true,
                height: 'auto',
                sortname: 'nombre',
                sortorder: 'desc',
                caption: "Usuarios",
                jsonReader: {
                    root: "rows",
                    total: "total",
                    page: "page",
                    records: "records",
                    repeatitems: false,
                    id: "user_id"
                },
            });            
        });
    </script>

和我的控制器:

    public JsonResult UsuariosGridData(string sidx = "" , string sord = "", int page = 1, int rows = 10)
    {
        var resultado = db_hms.Users//.OrderByDescending(ur => ur.id_user)
                        .Join(db_hms.v_natural_person_short, ur => ur.id_employee, np => np.id_natural_person, (ur, np) => new { Users = ur, Natural_Person = np })//cambiar el idUser por idEmployee la relacion es alrevez XD                            
                        .Select(s => new { user_id = s.Users.id_user, nombre = s.Natural_Person.name_full })
                        .ToList();



        int vpage = page;
        int vrows = rows;  
        int counter = (int)Math.Ceiling((float)resultado.Count() / (float)vrows);            
        switch (sidx)
        {
            case "nombre":
                {
                            if(sord == "desc")
                            {
                                resultado = resultado.OrderByDescending(s => s.nombre).Skip(vrows * vpage).Take(vrows).ToList();
                            }
                            else
                            {
                                resultado = resultado.OrderBy(s => s.nombre).Skip(vrows * vpage).Take(vrows).ToList(); ;
                            }
                    break;
                }
            case "user_id":
                {
                            if(sord == "desc")
                            {
                                resultado = resultado.OrderByDescending(s => s.user_id).Skip(vrows * vpage).Take(vrows).ToList();
                            }
                            else
                            {
                                resultado = resultado.OrderByDescending(s => s.user_id).Skip(vrows * vpage).Take(vrows).ToList();
                            }
                    break;
                }
        }
        var retornar = new
        {
            total = counter,
            page = vpage,
            records = vrows,
            rows = resultado
        };

        return Json(retornar, JsonRequestBehavior.AllowGet);

    }

和一个小的 json 示例:

and a small json example:

{"total":101,"page":1,"records":303,
 "rows":[{"user_id":"titito","nombre":"EL bonito, tito "},
        {"user_id":"noro","nombre":"ElMoro, Noro "},
        {"user_id":"maka","nombre":"Martinez, Macanencio "}]}

推荐答案

如果没有包含所需的语言文件 grid.locale-XX.js(例如 grid.locale-en.js) before jquery.jqGrid.min.jsjquery.jqGrid.src.js.请参阅文档中的jqGrid使用示例.

One get the error message typically if one don't included required language file grid.locale-XX.js (for example grid.locale-en.js) before jquery.jqGrid.min.js or jquery.jqGrid.src.js. See the example of the usage of jqGrid in the documentation.

此外,我建议您将 gridview: trueautoencode: true 选项添加到 jqGrid,删除不存在的 myType: 'GET' (有 mtype 选项,如果 "GET" 的默认值),将 jsonReader 减少到 jsonReader: {repeatitems: false, id: "user_id"},从 colModel 中删除所有 index 属性(因为你使用的值与 name 的值相同属性)并将 key: true 添加到 'user_id' 列的定义中.

Additionally I would recommend you to add gridview: true and autoencode: true option to jqGrid, remove non-existing myType: 'GET' (there are mtype option which default value if "GET"), reduce jsonReader to jsonReader: {repeatitems: false, id: "user_id"}, remove all index properties from colModel (because you use the values the same as the value of name property) and add key: true to definition of 'user_id' column.

因为您没有实现数据的服务器端分页,我建议您额外添加 loadonce: true 选项.它允许您一次从 UsuariosGridData 返回所有数据,jqGrid 将实现客户端排序、分页或可选的数据过滤/搜索.

Because you don't implemented server side paging of data I would recommend you add additionally loadonce: true option. It allows you to return all data at once from UsuariosGridData and jqGrid will implement client side sorting, paging or optionally filtering/searching of data.

这篇关于jqgrid 未定义整数?寻呼机未加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆