【问题标题】:How to load huge of data in kendo grid如何在剑道网格中加载大量数据
【发布时间】:2012-05-19 14:02:00
【问题描述】:

网络方法:

   <WebMethod()>
   Public Shared Function Pcpacking() As IEnumerable(Of Packing)
   Dim db As New STOREEntities
   Return db.PC_PACKING_HISTORIES. _
   Where(Function(q) q.PACK_DATE > "1388/11/07"). _
   Select(Function(q) New Packing _
              With {.Packdate = q.PACK_DATE,
                    .Packserialnumber = q.PACK_SERIAL_NUMBER,
                    .Netweight = q.NET_WEIGHT,
                    .Packusername = q.PACK_USER_NAME}).ToList()
   End Function

脚本:

$(function () {
       $("#grid").kendoGrid({
           height: 200,
           columns: [
                { field: "Packserialnumber", width: "150px" },
               { field: "Netweight", width: "50px" },
               { field: "Packusername", width: "150px" },
               { field: "Packdate", width: "100px" }
           ],
           editable: false,
           dataSource: {
               schema: {
                   data: "d",
                   model: {
                       id: "Packserialnumber",
                       fields: {
                           Packserialnumber: { editable: false, nullable: true },
                           Netweight: { type: "number", validation: { required: true, min: 1} },
                           Packusername: { validation: { required: true} },
                           Packdate: { validation: { required: true} }
                       }
                   }
               },
               batch: false,
               transport: {
                   read: {
                       url: "Default.aspx/Pcpacking",
                       contentType: "application/json; charset=utf-8",
                       type: "POST"
                   }
               }
           }
       });
   });

在这种情况下(PACK_DATE > "1388/11/07" 366 条记录)一切正常。但是当我将日期更改为 1388/11/06 1260 条记录或 1388/11/05 5460 条记录 或 ... 出现以下错误:

{"Message":"使用JSON JavaScriptSerializer进行序列化或反序列化时出错。字符串的长度超过了值 在 maxJsonLength 属性上设置。 ","StackTrace":" 在 System.Web.Script.Serialization.JavaScriptSerializer。 序列化(对象 obj,StringBuilder 输出,SerializationFormat 序列化格式)\r\n 在 System.Web.Script.Serialization.JavaScriptSerializer.Serialize(对象 对象, SerializationFormat 序列化格式)\r\n 在 System.Web.Script.Services.RestHandler.InvokeMethod(HttpContext 语境, WebServiceMethodData 方法数据,IDictionary`2 rawParams)\r\n
在 System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext 上下文,WebServiceMethodData 方法数据)", "ExceptionType":"System.InvalidOperationException"}

我认为剑道网格不支持大数据。有什么建议吗?
对不起我的英语不好。

【问题讨论】:

标签: jquery asp.net vb.net kendo-ui


【解决方案1】:

问题实际上是,默认情况下,如果生成的 JSON 字符串大于 100 kB,.NET JSON 序列化程序会抛出异常。显然,发送数千条记录大于限制。你可以change this setting,但我不会推荐它用于你的应用程序。

相反,将网格配置为一次请求小块数据。看来你可以configure Kendo Grid to load more data as you scroll

$("#grid").kendoGrid({
    dataSource: {
        type: "odata",
        serverPaging: true,
        serverSorting: true,
        pageSize: 100,
        transport: {
            read: {
                url: "Default.aspx/Pcpacking",
                contentType: "application/json; charset=utf-8",
                type: "POST"
            }
        }
    },
    scrollable: {
        virtual: true
    },

    ...
});

您的服务器端脚本必须处理 Kendo 发送的 top(要发送多少条记录)和 skip(从哪里开始)参数。

【讨论】:

    【解决方案2】:
    $(function () {
           $("#grid").kendoGrid({
               height: 200,
               columns: [
                    { field: "Packserialnumber", width: "150px" },
                   { field: "Netweight", width: "50px" },
                   { field: "Packusername", width: "150px" },
                   { field: "Packdate", width: "100px" }
               ],
               editable: false,
               dataSource: {
                   schema: {
                       data: "d",
                       model: {
                           id: "Packserialnumber",
                           fields: {
                               Packserialnumber: { editable: false, nullable: true },
                               Netweight: { type: "number", validation: { required: true, min: 1} },
                               Packusername: { validation: { required: true} },
                               Packdate: { validation: { required: true} }
                           }
                       }
                   },
                   batch: false,
                   transport: {
                       read: {
                           url: "Default.aspx/Pcpacking",
                           contentType: "application/json; charset=utf-8",
                           dataType: "json"
                       }
                   }
               }
           });
       });
    

    【讨论】:

    • 您应该编辑您的原始答案,而不是重新发布它。对问题及其解决方法的解释也很有帮助。
    猜你喜欢
    • 1970-01-01
    • 2018-06-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-03
    • 1970-01-01
    相关资源
    最近更新 更多