Kendo电子表格第一次没有使用JSON绑定

时间:2018-08-16 12:13:56

标签: json ajax asp.net-mvc kendo-ui

我有一个剑道电子表格,刷新后不会第一次在浏览器中加载。我已经在Google中搜索了很多,但找不到任何解决方案。请帮助我解决该问题。我正在使用asp.net mvc。

我的电子表格代码低于

 var customVal = $("#customInput").data("value");
        var CellCount = $('#sessionDivCount').attr('data-id');
        var headercount = '1';
        var displayCount = Number(CellCount) + Number(headercount);

        $(function () {
            var shouldPopulateHeader = true;
            var dataSource = new kendo.data.DataSource({

                requestEnd: function (e) {
                    setTimeout(function (e) {
                        if (shouldPopulateHeader) {
                            shouldPopulateHeader = false;

                            var spreadsheet = $("#spreadsheet").data("kendoSpreadsheet");
                            var sheet = spreadsheet.activeSheet();
                            // Change the default headers for the first and the second column
                                sheet.batch(function () {
                                sheet.range("A1").value("Order ID");
                                sheet.range("D1").value("Check/Receipt/Reference/Confirmation Number");
                                sheet.range("E1").value("Date Check Was Made Made/Payment Was Maid");
                                sheet.range("F1").value("Agent Payment Confirmation");
                                sheet.range("G1").value("Estimated payment Arrival Date");

                                sheet.range("A1:A16384 ").enable(false);
                                sheet.range("A2:A16384 ").textAlign = "center";
                                sheet.range("B1:B16384 ").enable(false);
                                var range = sheet.range("A2:A16384"); // 2x2 cell range
                                range.bold = true;
                                range.textAlign = "center";
                                range.color("green");


                                var range1 = sheet.range("B2:B16384"); // 2x2 cell range
                                range1.bold = true;
                                range1
                                range1.textAlign = "center";
                                range1.color("black");
                                range1.defaultValue = null;
                                sheet.range("c2").textAlign = "center";
                            }, { recalc: true });
                        }
                    }, 0);
                },
                transport: {
                    read: onRead,
                    submit: onSubmit
                },
                batch: true,
                change: function () {
                    $("#cancel, #save").toggleClass("k-state-disabled", !this.hasChanges());
                },
                schema: {
                    model: {
                        OrderID: "OrderID",
                        fields: {
                            OrderID: {
                                type: "number",
                                defaultValue: null
                            },
                            PO: {
                                type: "string",
                                defaultValue: null
                            },
                            Method: {
                                type: "string",

                            },
                            Check_Receipt_Refernce_confirmation_Number: {
                                type: "string"

                            },
                            DateCheck_Was_Mailed_Payment_Was_Made: {
                                type: "date"
                            },
                            Agent_Payment_Confirmation: {
                                type: "string"
                            },
                            Estimated_Payment_Arrival_Date: {
                                type: "date"
                            },

                        }
                    }
                }
            });

            $("#spreadsheet").kendoSpreadsheet({
                columns: 7,
                rows: displayCount,
                toolbar: true,
                sheetsbar: false,
                sheets: [{
                    name: "Products",
                    dataSource: dataSource,
                    rows: [{
                        height: 20,
                        cells: [
                            {
                                value: "Order ID",
                                bold: "true",
                                background: "#9c27b0",
                                textAlign: "center",
                                color: "white",
                                hidden: true,
                                enable: false
                            }, {
                                bold: "true",
                                background: "#9c27b0",
                                textAlign: "center",
                                color: "white",
                                enable: false
                            }, {
                                bold: "true",
                                background: "#9c27b0",
                                textAlign: "center",
                                color: "white",
                                enable: false
                            }, {
                                bold: "true",
                                background: "#9c27b0",
                                textAlign: "center",
                                color: "white",
                                enable: false
                            },
                            {
                                bold: "true",
                                background: "#9c27b0",
                                color: "white",
                                textAlign: "center",
                                enable: false
                            },
                            {
                                bold: "true",
                                background: "#9c27b0",
                                textAlign: "center",
                                color: "white"
                            }, {
                                bold: "true",
                                background: "#9c27b0",
                                textAlign: "center",
                                color: "white"
                            }
                        ]
                    }],
                    columns: [
                        { width: 145 },
                        { width: 145 },
                        { width: 145 },
                        { width: 300 },
                        { width: 300 },
                        { width: 300 },
                        { width: 300 }

                    ]
                }]
            });

            function onSubmit(e) {
                var arrofId = new Array();
                var models = {};
                var obj = "";
                for (i = 0; i < JSON.stringify(e.data.created.length); i++) {
                    obj = e.data.created[i];
                    arrofId.push(obj);
                }
                arrofId.push(obj);
                $.ajax({
                    type: "POST",
                    url: "/Agent/GetDataSpreadSheetSubmit1",
                    data: '{models: ' + JSON.stringify(arrofId) + '}',
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (result) {
                        alert('Record Saved Succesfully');
                        $('#grid').data('kendoGrid').dataSource.read();
                        $('#grid').data('kendoGrid').refresh();
                    },
                    error: function (xhr, httpStatusMessage, customErrorMessage) {
                        alert(xhr.responseText);
                    }
                });
            }

            function onRead(options) {
                $.ajax({
                    url: "../Agent/GetDataSpreadSheet",
                    type: "get",
                    dataType: "json",
                    success: function (result) {
                        debugger

                        options.success(result.data);
                        $("#spreadsheet").data("kendoSpreadsheet").refresh();
                    },
                    error: function (result) {
                        options.error(result);
                    }
                });
            }

            $("#save").click(function () {
                debugger
                if (!$(this).hasClass("k-state-disabled")) {
                    dataSource.sync();
                }
            });

            $("#cancel").click(function () {
                if (!$(this).hasClass("k-state-disabled")) {
                    dataSource.cancelChanges();
                }
            });
        });
    }

以下任何用于获取列表的控制器操作方法

[HttpGet]
        public ActionResult GetDataSpreadSheet()
        {
            int statusID = 50;         
            var list = agentLogic.GetListByStatusID_forSpreadSheet(statusID).OrderBy(p => p.OrderID).ThenBy(o => o.OrderID);            
            HttpContext.Session["CheckSpreadsheetCount"] = list.Count();            
            return Json(new { total = list.Count(), data = list }, JsonRequestBehavior.AllowGet);
        }

kendo电子表格不会第一次加载,但在重新加载浏览器后,它的工作将按预期进行。请帮我该怎么办?请帮助我,当它第一次在任何浏览器中加载时,仍然找不到任何解决方案,刷新后按预期工作会产生问题。

0 个答案:

没有答案