簡體   English   中英

Kendo Grid頁腳未在頁面加載時初始化

[英]Kendo Grid footer not initializing on page load

我正在使用Kendo UI網格來顯示從WCF服務消耗的結果。 我正在使用的Kendo版本是.web.2013.2.716.open-source。 我遇到一個問題,即頁面加載頁腳時尚未初始化。 它顯示0頁,沒有要顯示的項目。 該網格正在填充,並且確實包含有效行。 如果我對網格執行某種操作(例如排序)或更改每頁顯示的行數,則頁腳將包含有效信息。 這是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>

另外,這是用於網格的元素的標簽:

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

再次,正在填充網格,頁腳顯示在網格的底部,但是有0頁,並且頁腳指示“沒有要顯示的項目”。 但是,當我對網格進行排序或更改要顯示的行數時,頁腳隨后將顯示2頁和“ 1-5個(共9個項目)”。

任何人都可以提供與此問題有關的任何幫助,將不勝感激。

我看過標題為“網格分頁無法在頁面加載中工作”的文章。 在Kendo UI Premium論壇上並沒有任何幫助。

您很有可能沒有在響應中返回"total"

由於您在model定義中定義了一個名為total的字段,其中包含必須定義的total

服務器產生您說的內容的無效響應示例:

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

雖然這是一個有效的響應:

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

如果您實際上不願意發送總數,則將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" }
        }
    }
}

或更棘手但更簡單:

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