Uriel Arvizu
Uriel Arvizu

Reputation: 1916

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. 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.

Upvotes: 5

Views: 27237

Answers (3)

user4339579
user4339579

Reputation: 1

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

Upvotes: 0

Elaine Lin
Elaine Lin

Reputation: 541

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

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

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

Upvotes: 1

OnaBai
OnaBai

Reputation: 40917

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

Upvotes: 7

Related Questions