简体   繁体   English

Kendo UI Grid上的分页无法正常工作

[英]Pagination on Kendo UI Grid is not working

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. 这会呈现一个包含5个项目的网格,但就是这样,我无法浏览其余条目。 The number of pages and items to display is marked as zero, disabling the navigation controls. 要显示的页数和项目标记为零,禁用导航控件。

Am I missing something in my cofiguration? 我在配置中遗漏了什么吗? Thanks for any help you can provide. 感谢您的任何帮助,您可以提供。

When paging is done in the server (check serverpaging ), you need to return the total number of records. 在服务器中完成分页(检查serverpaging )时,需要返回记录总数。 See total for information. 有关信息,请参阅total

I had the same issue because I misunderstood serverPaging. 我遇到了同样的问题,因为我误解了serverPaging。 If you set serverPaging to true, you also have to modify what the server returns. 如果将serverPaging设置为true,则还必须修改服务器返回的内容。

Previously, I had the server returning all of the data. 以前,我让服务器返回所有数据。 To fix this, I used ToDataSourceResult to 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网格中实现服务器端分页

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;
      }

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

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