【问题标题】:KendoUI pagination throws exception and doesn't show page informationKendoUI 分页抛出异常并且不显示页面信息
【发布时间】:2014-02-27 08:06:01
【问题描述】:

我正在尝试让 KendoUI 网格与服务器端分页一起使用。到目前为止,我已经设法让网格从远程数据源读取数据并将分页/过滤信息正确发送到 MVC 控制器操作

这工作正常,但是,我根本看不到网格的分页控件。

我尝试将pageable: true 添加到网格的设置中,虽然这确实显示了寻呼机控件,但它不显示任何页面/总数并抛出一个 JS 对象不支持此属性或方法 当我尝试使用下一页/上一页按钮更改页面时。它正在寻找的方法是 'slice' - 我要看看未缩小的 kendo src 但同时我想我会在这里发帖

动作如下所示:

public ActionResult _Index(int? pageSize, int? skip, string filter = "")
{
    // Code that gets the data
    var data = ... (some Linq->Entities queries)
    var total = ... (total count of all the entities)

    return Json(new { total, data });
}

我正确地返回了总数,我检查了 JSON,它符合我的预期(以及网格应该预期的)

网格设置是这样的:

$(document).ready(function () {
    var grid = $("#itemList").kendoGrid({
        toolbar: kendo.template($("#template").html()),
        columns: ["Manufacturer", "Model", "Price", "Tags"],
        dataSource: {
            transport: {
                read: {
                    url: "catalogadmin/_index",
                    dataType: "json",
                    type: "POST",
                    data: {
                        filter: ""
                    }
                },
            },
            schema: {
                data: "data", // records are returned in the "data" field of the response
                total: "total" // total number of records is in the "total" field of the response
            },
            pageSize: 2,
            serverPaging: true
        },
        pageable: true
});

我将 pageSize 设置为 2 以测试分页(因为我现在数据库中只有 4 个项目)

JSON 是:

{"total":4,"data":[{"Id":6,"Manufacturer":"hello","Model":";lmqw;lemwqe","Price":4.00,"ShortDescription":"world","Tags":[],"Used":false}]}

我不认为这是问题所在 - 似乎您需要设置 pageable: true 才能使分页工作 - 但我认为分页甚至不适用于客户端数据,我只是要检查现在

编辑:我已经检查过了,客户端分页也不起作用。尝试分页时,我收到“无法获取未定义或空引用的 toLowerCase 属性”。寻呼机看起来像服务器端页面,没有数据,没有页码,没有总计。

我认为 Kendo 没有完全正确注册 - 我有最新版本(刚刚下载)但没有雪茄...

【问题讨论】:

  • 您能否编辑问题并显示您的服务正在返回的 JSON?

标签: asp.net-mvc-4 kendo-ui pagination


【解决方案1】:

已排序 - 不知道为什么,但是当我使用 Teleriks 'convert to Kendo UI project' 安装 KendoUI 时,它同时注册了 kendo.all.min.js 文件和 mvc/dataviz 文件。

我删除了额外的脚本引用,现在一切正常!

【讨论】:

    猜你喜欢
    • 2013-11-13
    • 2013-08-02
    • 2019-02-25
    • 1970-01-01
    • 2022-06-16
    • 1970-01-01
    • 2023-03-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多