javascript - Kendo UI 网格始终从第 0 页开始

标签 javascript jquery kendo-ui

我有一个 Kendo UI Grid,它总是从 0 开始。

如果我更改列的排序,则它会转到 1 并显示其他页码。

我做错了什么?

这是我的代码:

$('#userGrid').kendoGrid({
                dataSource: {
                    pageSize: 5,
                    transport: {
                        read: {
                            url: ROOT+"user/user-list",
                        },
                        update: {
                            url: ROOT+"user/update-user",
                            dataType: "POST"
                        }
                    },
                    error: function(e) {
                        alert(e.responseText);
                    },
                    schema: {
                        data: "data",
                        model: {
                            id: 'id',
                            fields: {
                                username: {type: "string", editable: false},
                                type: {
                                    type: "number",
                                    editable: true,
                                    validation: {required: true}
                                },
                                level: {
                                    type: "number",
                                    editable: true,
                                    validation: {required: true}
                                },
                                firstName: {type: "string", editable: true},
                                middleName: {type: "string", editable: true},
                                lastName: {type: "string", editable: true},
                                DoB: {type: "date", editable: true},
                                dateStarted: {type: "date", editable: false},
                                enabled: {
                                    type: "number",
                                    editable: true,
                                    validation: {required: true}
                                },
                            }
                        }
                    }
                },
                toolbar: ["save", "cancel"],
                sortable: true,
                pageable: {
                    refresh: true,
                    pageSizes: false
                },
                editable:true,
                columns:
                [
                    {
                    field: "username",
                    width: 90,
                    title: "Username"
                    },
                    {
                    field: "type",
                    width: 50,
                    title: "Type"
                    },
                    {
                    field: "level",
                    width: 25,
                    title: "Level"
                    },
                    {
                    field: "firstName",
                    width: 50,
                    title: "First name"
                    },
                    {
                    field: "middleName",
                    width: 50,
                    title: "Middle name"
                    },
                    {
                    field: "lastName",
                    width: 50,
                    title: "Last name"
                    },
                    {
                    field: "DoB",
                    width: 40,
                    title: "DoB",
                    template: '#= kendo.toString(DoB,"dd/MM/yyyy") #'
                    },
                    {
                    field: "dateStarted",
                    width: 40,
                    title: "Started",
                    template: '#= kendo.toString(dateStarted,"dd/MM/yyyy") #'
                    },
                    {
                    field: "enabled",
                    width: 40,
                    title: "Enabled"
                    }
                ]
            })
        })
    }
) ;
})

{"data":[{"id":"1","username":"admin@eu","type":"1","level":"12","firstName":"Tom","middleName":"C","lastName":"Higgins","DoB":"0000-00-00","dateStarted":"0000-00-00","enabled":"0"},{"id":"36","username":"liam.spelman@euautomation.com","type":"4","level":"12","firstName":"Liam","middleName":"","lastName":"Spelman","DoB":"0000-00-00","dateStarted":"0000-00-00","enabled":"0"},{"id":"56","username":"adf@sadf.com","type":"4","level":"1","firstName":"asdf","middleName":"","lastName":"asdf","DoB":"1970-01-01","dateStarted":"0000-00-00","enabled":"0"},{"id":"57","username":"adf@saddf.com","type":"4","level":"1","firstName":"asdf","middleName":"","lastName":"asdf","DoB":"1970-01-01","dateStarted":"0000-00-00","enabled":"0"}], "rowcount": 4}

最佳答案

您的服务器是否返回了总数 的记录?

如果是,将 schema 定义为(假设 total_size 是服务器返回记录总数的位置):

schema   : {
    data: "data",
    total: "total_size",
    model: {
        ...
    }
}

如果没有,请尝试向您的schema 添加一个total 函数,该函数从data 数组的大小中获取它:

schema   : {
    data: "data",
    total: function(data) {
        return data.data.length;
    },
    model: {
        ...
    }
}

关于javascript - Kendo UI 网格始终从第 0 页开始,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14253912/

相关文章:

javascript - 更改堆栈条形图中的起点

javascript - 使用Kendo Bullet Graph如何将目标线更改为虚线?

javascript - 如何使用 SystemJS 在 Angular2 应用程序中加载 bootstrap.js、jQuery 和其他模块

javascript - jQuery AutoNumeric 不格式化多个字段

javascript - 在不重新创建标记的情况下测试 JavaScript 代码?

javascript - jquery 下拉菜单不起作用

javascript - 我们可以在初始化后更改 Kendo Tree 传输读取 URL

javascript - Webpack 脚本不会通过 NPM 运行,但如果直接粘贴到终端就会运行

javascript - 如何在 Angular NgRepeat 中访问循环变量

.net - 动态添加客户端脚本/HTML 调用服务器端事件