首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用MVC 4处理3200多个记录时显示空的JQGrid

使用MVC 4处理3200多个记录时显示空的JQGrid
EN

Stack Overflow用户
提问于 2016-02-12 14:04:16
回答 2查看 530关注 0票数 0

JQGrid可以很好地处理3000多条记录,所以使用loadone:true,虽然超过3200条,但它显示的是空网格。我想讨论一下服务器端分页和加载一次:false。是否有更好的方法来加载一次数据:true并显示一些海量的数据,比如20k记录?如果我们要使用服务器端分页,我们应该只从数据库中获取特定数量的记录?请在下面找到我的代码,如果有任何问题请给我指点。

模型:

代码语言:javascript
运行
复制
public class GOALogging
{
    public int SERV_TRANS_ID { get; set; }
    public string ACT_YEAR  { get; set; }
    public string SEAS { get; set; }
    public string RESPONSE_DT { get; set; }
}

控制器

代码语言:javascript
运行
复制
  public ActionResult Index()
  {
      return View();
  }

 public JsonResult getRecords()
  {
      List<GOALogging> items = new List<GOALogging>();
      items = GetLoggingDetails();
      var a = Json(items, JsonRequestBehavior.AllowGet);
      return a;
  }

public List<GOALogging> GetLoggingDetails()
    {
        string connString = ConfigurationManager.ConnectionStrings["ACTOLConnection"].ConnectionString;
        SqlConnection conn = new SqlConnection(connString);
        SqlCommand cmd = new SqlCommand();
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.CommandTimeout = 6000;
        cmd.CommandText = "GET_SAMPLEDETAILS";
        cmd.Connection = conn;
        conn.Open();
        DataTable dataTable = new DataTable();
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        da.Fill(dataTable);
        conn.Close();
        da.Dispose();

        List<GOALogging> items = new List<GOALogging>();
        foreach (DataRow row in dataTable.Rows)
        {
            items.Add(new GOALogging
            {
                SERV_TRANS_ID = Convert.ToInt32(row["SERV_TRANS_ID"]),
                ACT_YEAR = row["ACT_YEAR"].ToString(),
                SEAS = row["SEAS"].ToString(),
                RESPONSE_DT = row["RESPONSE_DT"].ToString()
            });
        }
        return items;
    }

视图

代码语言:javascript
运行
复制
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
<script src="~/Scripts/grid.locale-en.js"></script>
<script src="~/Scripts/jquery-1.11.0.min.js"></script>
<link href="~/Scripts/lib-UI-jquery-css-custom-theme-jquery-ui-1.9.2.custom.css" rel="stylesheet" />
<script src="~/Scripts/jquery.jqGrid.js"></script>
<script src="~/Scripts/grid.locale-en.js"></script>
<link href="~/Scripts/ui.jqgrid.css" rel="stylesheet" />
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.13/themes/base/jquery-ui.css" rel="stylesheet" />
</head>
<body>
<script type="text/javascript">
    $(function () {
        $("#myGrid").jqGrid({
            url: '/GOA/getRecords',
            datatype: 'json',
            myType: 'GET',
            colNames: ['ID',
                'YEAR', 'SEASON', 'RESPONSE_DT'],
            colModel: [
            { name: 'SERV_TRANS_ID' },
            { name: 'ACT_YEAR' },
            { name: 'SEAS' },
            { name: 'RESPONSE_DT' }
            ],
            pager: $('#myPager'),
            jsonReader: { cell: ""},
            rowNum: 10,
            sortname: 'SERV_TRANS_ID',
            sortorder: 'desc',
            gridview: true,
            loadonce: true,
            rowList: [10, 20, 50, 100],
            width:1120,
            height:280,
            viewrecords: true,
            caption: 'Past 24 hours ACTService Processing Status'
        });
    });
</script>
<div >
    <table id="myGrid" ></table>

    <div id="myPager"></div>
</div>
</body>
</html>
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-02-29 08:17:21

这是由于.Net中的最大长度限制,您可以在控制器中使用下面的格式化代码来提前处理问题。

代码语言:javascript
运行
复制
        List<MEmployee> items = new List<MEmployee>();
        items = getData();
        var a = Json(items, JsonRequestBehavior.AllowGet);
        a.MaxJsonLength = int.MaxValue;
        return a;

参考链接

票数 1
EN

Stack Overflow用户

发布于 2016-02-12 14:34:33

我怀疑您对序列化数据的大小有一些问题。我的意思是,您有纯粹的ASP.NET MVC问题。旧版本的ASP.NET MVC使用非常老的JavaScriptSerializer进行序列化,这具有描述这里这里的限制。

我建议您使用Newtonsoft.Json而不是JavaScriptSerializer。如果要迁移到MVC5,那么它将是自动的。Newtonsoft.Json的工作速度比JavaScriptSerializer快得多,而且没有这样的限制。

这里您可以下载使用简单的ASP.NET MVC编辑数据的演示项目。它使用的是自然的Newtonsoft.Json

此外,还建议使用对返回的JSON数据的压缩。例如,看看这里

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35364531

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档