剑道网格页脚模板总和问题

时间:2016-07-26 13:42:12

标签: jquery-ui asp.net-mvc-5 kendo-asp.net-mvc

      var dataSourceDashboard = new kendo.data.DataSource({
                    pageSize: 20,
                    type: "json",
                    transport: {
                        read: function (operation) {
                            if (navigator.onLine) {
                                $.ajax({
                                    url: '/Home/Dashboard_Read/',
                                    type: "GET",
                                    dataType: "json",
                                    success: function (response) {

                                        try
                                        {
                                            localStorage.setItem("Dashboard_Read", JSON.stringify(response));
                                        }
                                        catch (domException)
                                        {
                                            if (domException.name === 'QuotaExceededError' ||
                                                domException.name === 'NS_ERROR_DOM_QUOTA_REACHED') {
                                                // Fallback code comes here.
                                                $("#progressMsgError").html("Cannot save the data for offline use, please clear the cache, or call administrator!");
                                                $('#myModalError').modal('show');
                                            }
                                        }

                                        operation.success(response);
                                        BindSitesCombo(response);




                                        //// initial sync of data
                                        //var cashedDataBaseJson = [];
                                        //var cashedDataBase = localStorage.getItem("cashedDataBase");
                                        //if (cashedDataBase != null || cashedDataBase != undefined) {
                                        //    cashedDataBaseJson = JSON.parse(cashedDataBase);
                                        //    if (cashedDataBaseJson.length > 0) {
                                        //        syncInitialData(cashedDataBaseJson);
                                        //        localStorage.setItem("cashedDataBase", JSON.stringify(cashedDataBaseJson));
                                        //    }
                                        //}
                                        //else
                                        //{
                                        //    syncInitialData(response);
                                        //    localStorage.setItem("cashedDataBase", JSON.stringify(response));
                                        //}


                                        var cashedDataBase = localStorage.getItem("cashedDataBase");
                                        if (cashedDataBase == null || cashedDataBase == undefined) {
                                            localStorage.setItem("cashedDataBase", JSON.stringify(response));
                                        }
                                        else {

                                            var cashedDataBaseJson = [];
                                            var cashedDataBase = localStorage.getItem("cashedDataBase");
                                            if (cashedDataBase != null || cashedDataBase != undefined) {
                                                cashedDataBaseJson = JSON.parse(cashedDataBase);

                                                var i = response.length;
                                                while (i--) 
                                                {
                                                    var ifsiteisinthelist = contains(cashedDataBaseJson, response[i]);
                                                    if (ifsiteisinthelist == false)
                                                    {
                                                        cashedDataBaseJson.push(response[i]);
                                                    }
                                                }

                                                localStorage.setItem("cashedDataBase", JSON.stringify(cashedDataBaseJson));


                                            }

                                        }

                                        rempvesyncedlinks();

                                    },
                                    error: function (response)
                                    {
                                        window.location.href = "/account/login";
                                    }
                                });
                            }
                            else {
                                var cashedData = localStorage.getItem("Dashboard_Read");
                                if (cashedData != null || cashedData != undefined) {
                                    //if local data exists load from it
                                    var data = JSON.parse(cashedData);
                                    operation.success(data);
                                    BindSitesCombo(data);
                                    rempvesyncedlinks();
                                }
                            }
                        }
                    },
                    schema: {
                        model: {
                            id: "SiteID",
                        }
                    },

                    //change: function (e) {
                    //    $.each(dataSourceDashboard.data(), function (index, value) {
                    //        $('#cmbAllSites')
                    //            .append($("<option></option>")
                    //            .attr("value", value.SiteID)
                    //            .text(value.SiteName));
                    //    });
                    //}

                    change: function (e) {
                        rempvesyncedlinks();
                    },
                    aggregate: [
                     { field: "DailyTotalFormated", aggregate: "sum" },
                     { field: "WeeklyTotalFormated", aggregate: "sum" },
                     { field: "WeeklySiteTotalFormated", aggregate: "sum" },
                     { field: "WeeklyGoal", aggregate: "sum" }
                    ],
                });

 $(function () {
            $("#gridDashboard").kendoGrid({
                dataSource: dataSourceDashboard,
                filterable: false,
                groupable: false,
                toolbar: false,
                pageable: {                    
                    change: function (e) {
                        rempvesyncedlinks();                        
                    }
                },
                sortable: true,
                height: 600,
                columns: [
                    { field: "SiteName", title: "MY COMPANIES", template: '<a href="##" onclick="setSiteID(#=SiteID#, \'#=SiteLogo#\', \'#=SiteName#\'); return false;">#=SiteName#</a>',footerTemplate: "Total "  },
                    { field: "DailyTotalFormated", title: "MY DAILY TOTAL", aggregates: ["sum"], footerTemplate: "#=sum#" },
                    { field: "WeeklyTotalFormated", title: "MY WEEKLY TOTAL", aggregates: ["sum"], footerTemplate: "#=sum#" },
                    { field: "WeeklySiteTotalFormated", title: "WEEKLY SITE TOTAL", aggregates: ["sum"], footerTemplate: "#=sum#" },
                    { field: "WeeklyGoal", title: "WEEKLY SITE GOAL", aggregates: ["sum"], footerTemplate: "#=sum#" },
                    { field: "", title: "SYNC", template: "# if (isSynced == true) { #" +
                        "<div style='width: 130px;margin: auto;'><img src='/images/ready.png' alt='Up-to-date' /><div style='font-size:15px; font-weight:bolder; float: right;'>Ready</div></div>" +
                        "# } else { #" +
                        "<div style='width: 130px;margin: auto;'><img src='/images/pleasesync.png' alt='Up-to-date' /><div style='font-size:15px; font-weight:bolder; float: right;'>Please Sync</div></div>" +
                        "# } #  <a id='syncforoffline#=SiteID#' href='##' onclick='syncDataForSite(#=SiteID#);return false;'>Sync for offline</a>"
                    },
                    { field: "SiteLogo", title: " ", hidden : true },

                    ],
                editable: false
            });


            $("#cmbAllSites").change(function ()
            {
                var di = dataSourceDashboard.data()[this.selectedIndex - 1];
                setSiteID(di.SiteID, di.SiteLogo, di.SiteName);                
            });
        });

Footer sum is not calculated

此代码有什么问题,为什么总显示最后一行?

1 个答案:

答案 0 :(得分:0)

我解决了这个问题。我只想补充一下:

                    model: {
                        id: "SiteID",
                        fields: {
                            SiteName: { type: "string" },
                            DailyTotalFormated: { type: "number" },
                            WeeklyTotalFormated: { type: "number" },
                            WeeklySiteTotalFormated: { type: "number" },
                            WeeklyGoal: { type: "number" }

                        }
                    }