Javascript Kendo UI Grid 上的分页不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14821988/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 18:02:10  来源:igfitidea点击:

Pagination on Kendo UI Grid is not working

javascriptkendo-uikendo-grid

提问by Uriel Arvizu

I'm displaying a grid with remote data, if I don't add pagination the full set of data is displayed, of course this is not desired.

我正在显示带有远程数据的网格,如果我不添加分页,则会显示完整的数据集,当然这不是我们想要的。

The following is the code I'm using to display data on a grid:

以下是我用来在网格上显示数据的代码:

var ds = new kendo.data.DataSource({
    transport: {
        read: {
            url: "http://127.0.0.1:81/SismosService.svc/usuario/index",
            dataType: "json"
        }
    },
    schema: {
        data: "Response"
    },
    pageSize: 5
});
$("#usuariosGrid").kendoGrid({
    pageable: {
        refresh: true
    },
    columns: [
        { field: "UsuarioId", title: "ID", width: "100px" },
        { field: "Nombre", title: "Nombre", width: "100px" },
        { field: "ApellidoP", title: "Apellido Paterno", width: "100px" },
        { field: "ApellidoM", title: "Apellido Materno", width: "100px" },
        { command: [{ text: "Editar", click: editFunction }, { text: "Eliminar", click: deleteFunction }], title: " ", width: "200px" }
    ],
    dataSource: ds
});

This renders a grid with 5 items on it, but that's it, I can't navigate through the rest of the entries. The number of pages and items to display is marked as zero, disabling the navigation controls.

这将呈现一个包含 5 个项目的网格,但仅此而已,我无法浏览其余条目。要显示的页面和项目数标记为零,从而禁用导航控件。

Am I missing something in my cofiguration? Thanks for any help you can provide.

我的配置中是否缺少某些东西?感谢您的任何帮助,您可以提供。

回答by OnaBai

When paging is done in the server (check serverpaging), you need to return the total number of records. See totalfor information.

在服务器中完成分页时(检查serverpaging),您需要返回记录总数。有关total信息,请参阅。

回答by Elaine Lin

I had the same issue because I misunderstood serverPaging. If you set serverPaging to true, you also have to modify what the server returns.

我遇到了同样的问题,因为我误解了 serverPaging。如果将 serverPaging 设置为 true,则还必须修改服务器返回的内容。

Previously, I had the server returning all of the data. To fix this, I used ToDataSourceResultto modify what my server returns.

以前,我让服务器返回所有数据。为了解决这个问题,我曾经ToDataSourceResult修改过我的服务器返回的内容。

See: How to implement Server side paging in Client side Kendo UI grid in asp.net mvc

请参阅: 如何在 asp.net mvc 中的客户端 Kendo UI 网格中实现服务器端分页

回答by user4339579

spend a day on this minor issue, all you have to do is return the total number of records, if your service doesn't return the total number of records, do the following

花一天时间在这个小问题上,你所要做的就是返回记录总数,如果你的服务没有返回记录总数,请执行以下操作

schema: {
        data: "Response"
    },

total: function(response)
      {
        return response."your method name".length;
      }