简体   繁体   English

Kendo Grid页脚未在页面加载时初始化

[英]Kendo Grid footer not initializing on page load

I am using Kendo UI Grid to display results consumed from a WCF service. 我正在使用Kendo UI网格来显示从WCF服务消耗的结果。 The version of Kendo that I am using is .web.2013.2.716.open-source. 我正在使用的Kendo版本是.web.2013.2.716.open-source。 I am having an issue that when the page loads the footer has not been initialized. 我遇到一个问题,即页面加载页脚时尚未初始化。 It is showing 0 pages and no items to display. 它显示0页,没有要显示的项目。 There grid is being populated and does contain valid rows. 该网格正在填充,并且确实包含有效行。 If I perform any kind of action on the grid such as a sort or change the number of rows to display per page the footer then contains valid information. 如果我对网格执行某种操作(例如排序)或更改每页显示的行数,则页脚将包含有效信息。 Here is a copy of the JavaScript code: 这是JavaScript代码的副本:

<script>
    $(document).ready(function () {
        $("#customerGrid").kendoGrid({
            autoBind:true,
            dataSource: {
                change: function (results) {
                    console.log("Successful");
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    console.log(textStatus)
                },
                transport: {
                    read: "/Services/SalesCRM_DBServices.svc/getCustomers",
                    dataType: "json"
                },
                schema: {
                    data: function (response) {
                        return response.d;
                    },
                    total:"total",
                    model: {
                        fields: {
                            AccountNumber: { type: "string" },
                            Name: { type: "string" },
                            ContactName: { type: "string" }
                        }
                    }
                },
            },
            height:325,
            filterable: true,
            sortable: true,
            serverPaging:true,
            pageable: {
                refresh: false,
                info: true,
                input: true,
                numeric: true,
                pageSize:5,
                pageSizes: true,
                previousNext: true
            },
            columns: [{
                field: "AccountNumber",
                title: "Account Number",
                width: "125px",
                filterable: false
            },
            {
                field: "Name",
                title: "Name",
                width: "200px",
                filterable: false
            },
            {
                field: "ContactName",
                title: "Contact Name",
                width: "200px",
                filterable: false
            },
            {
                command: [{ text: "SELECT" }],
                width: "50px"
            },
            ],
        });

    });
</script>

Also, here is the tag of the element being used for the grid: 另外,这是用于网格的元素的标签:

<div id="customerGrid"></div>

Again, grid is being populated, footer is showing at bottom of the grid, but there are 0 pages and the footer indicates that "No items to display". 再次,正在填充网格,页脚显示在网格的底部,但是有0页,并且页脚指示“没有要显示的项目”。 But, when I sort the grid or change the number of rows to display, the footer then shows 2 pages and "1 - 5 of 9 items". 但是,当我对网格进行排序或更改要显示的行数时,页脚随后将显示2页和“ 1-5个(共9个项目)”。

Any, assistance that anyone could provide concerning this issue would be greatly appreciated. 任何人都可以提供与此问题有关的任何帮助,将不胜感激。

I have looked at the post titled "Grid paging not working on page load." 我看过标题为“网格分页无法在页面加载中工作”的文章。 on the Kendo UI Premium Forum and it was not really any help. 在Kendo UI Premium论坛上并没有任何帮助。

Very likely you are not returning "total" in the response. 您很有可能没有在响应中返回"total"

Since you define in the model definition that there is a field called total that contains the total you have to define it. 由于您在model定义中定义了一个名为total的字段,其中包含必须定义的total

Example of invalid response from the server producing what you say: 服务器产生您说的内容的无效响应示例:

{
    "d"    : [
        { "AccountNumber": 1, "Name": "John", "ContactName": "Jack" },
        { "AccountNumber": 2, "Name": "Jane", "ContactName": "Jack" },
        { "AccountNumber": 3, "Name": "Joe", "ContactName": "Jack" }
    ]
}

While this is a valid response: 虽然这是一个有效的响应:

{
    "total": 3,
    "d"    : [
        { "AccountNumber": 1, "Name": "John", "ContactName": "Jack" },
        { "AccountNumber": 2, "Name": "Jane", "ContactName": "Jack" },
        { "AccountNumber": 3, "Name": "Joe", "ContactName": "Jack" }
    ]
}

If you are actually not willing to send the total then define the Model as: 如果您实际上不愿意发送总数,则将Model定义为:

schema   : {
    data : function (response) {
        return response.d;
    },
    total: function (response) {
        return response.d.length;
    },
    model: {
        fields: {
            AccountNumber: { type: "string" },
            Name         : { type: "string" },
            ContactName  : { type: "string" }
        }
    }
}

or trickier but simpler: 或更棘手但更简单:

schema   : {
    data : "d",
    total: "d.length",
    model: {
        fields: {
            AccountNumber: { type: "string" },
            Name         : { type: "string" },
            ContactName  : { type: "string" }
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM