This is a migrated thread and some comments may be shown as answers.

Client side paging does not work if DataSource is defined outside of grid.

2 Answers 205 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Shea
Top achievements
Rank 1
Shea asked on 25 Apr 2013, 12:50 AM
If I define my data source independantly of my grid, the paging on the grid doesn't work. I have wasted a couple hours figuring out what the problem is. I can put the data source as part of a grid in this case, though it does make code slightly messier.

$(document).ready(function () {
    var src = new kendo.data.DataSource({
        transport: {
            read: {
                url: "Handlers/TaskHandler.ashx",
                dataType: "json",
                type: "GET",
            },
            update: {
                url: "Handlers/TaskHandler.ashx",
                dataType: "json",
                type: "PUT",
            },
            destroy: {
                url: "Handlers/TaskHandler.ashx",
                dataType: "json",
                type: "DELETE",
            },
            create: {
                url: "Handlers/TaskHandler.ashx",
                dataType: "json",
                type: "POST",
            },
            parameterMap: function (options, operation) {
                if (operation !== "read" && options.models) {
                    return { tasks: kendo.stringify(options.models) };
                }
            }
        },
 
        batch: true,
 
        schema: {
            model: {
                id: "Id",
                fields: {
                    Id: { editable: false, nullable: true },
                    Description: { type: "string", editable: true },
                    IsComplete: { type: "boolean", editable: true },
                    Priority: { type: "number", editable: true },
                    CreatedOn: { type: "date", editable: false, defaultValue: new Date() }
                }
            }
        },
    });
 
    $('#task-data').kendoGrid({
        toolbar: ["create", "save", "cancel"],
 
        columns: [
            {
                field: "Id",
                width: 44,
                title: "ID"
            }, {
                field: "Description",
            }, {
                field: "Priority",
                width: 110,
                title: "Prio"
            }, {
                field: "IsComplete",
                width: 90,
                title: "Complete"
            } , {
                field: "CreatedOn",
                width: 120,
                title: "Created",
                format: "{0:yyyy-MM-dd}"
            }, {
                command: ["destroy"], title: "", width: 120
            }
        ],
 
        pageable: {
            pageSize: 5
        },
 
        scrollable: true,
        editable: true,
        navigatable: true,
        sortable: true,
 
        dataSource: src
        //dataSource: {
        //    transport: {
        //        read: {
        //            url: "Handlers/TaskHandler.ashx",
        //            dataType: "json",
        //            type: "GET",
        //        },
        //        update: {
        //            url: "Handlers/TaskHandler.ashx",
        //            dataType: "json",
        //            type: "PUT",
        //        },
        //        destroy: {
        //            url: "Handlers/TaskHandler.ashx",
        //            dataType: "json",
        //            type: "DELETE",
        //        },
        //        create: {
        //            url: "Handlers/TaskHandler.ashx",
        //            dataType: "json",
        //            type: "POST",
        //        },
        //        parameterMap: function (options, operation) {
        //            if (operation !== "read" && options.models) {
        //                return { tasks: kendo.stringify(options.models) };
        //            }
        //        }
        //    },
 
        //    batch: true,
 
        //    schema: {
        //        model: {
        //            id: "Id",
        //            fields: {
        //                Id: { editable: false, nullable: true },
        //                Description: { type: "string", editable: true },
        //                IsComplete: { type: "boolean", editable: true },
        //                Priority: { type: "number", editable: true },
        //                CreatedOn: { type: "date", editable: false, defaultValue: new Date() }
        //            }
        //        }
        //    },
        //}
    });
});
If I switch the code back to using the inline definition of the data source then the paging works.

The docs make no mention of this. Is it a bug?

2 Answers, 1 is accepted

Sort by
0
Accepted
HUA
Top achievements
Rank 1
answered on 25 Apr 2013, 06:11 AM
Hi Shea,
I think if you mention into the datasource the pagesize setting and set into the the grid peageable:true,this will work.
$(document).ready(function () {
    var src = new kendo.data.DataSource({
        transport: {
            read: {
                url: "Handlers/TaskHandler.ashx",
                dataType: "json",
                type: "GET",
            },
            update: {
                url: "Handlers/TaskHandler.ashx",
                dataType: "json",
                type: "PUT",
            },
            destroy: {
                url: "Handlers/TaskHandler.ashx",
                dataType: "json",
                type: "DELETE",
            },
            create: {
                url: "Handlers/TaskHandler.ashx",
                dataType: "json",
                type: "POST",
            },
            parameterMap: function (options, operation) {
                if (operation !== "read" && options.models) {
                    return { tasks: kendo.stringify(options.models) };
                }
            }
        },
  
        batch: true,
       pageSize:5,
        schema: {
            model: {
                id: "Id",
                fields: {
                    Id: { editable: false, nullable: true },
                    Description: { type: "string", editable: true },
                    IsComplete: { type: "boolean", editable: true },
                    Priority: { type: "number", editable: true },
                    CreatedOn: { type: "date", editable: false, defaultValue: new Date() }
                }
            }
        },
    });
  
    $('#task-data').kendoGrid({
        toolbar: ["create", "save", "cancel"],
  
        columns: [
            {
                field: "Id",
                width: 44,
                title: "ID"
            }, {
                field: "Description",
            }, {
                field: "Priority",
                width: 110,
                title: "Prio"
            }, {
                field: "IsComplete",
                width: 90,
                title: "Complete"
            } , {
                field: "CreatedOn",
                width: 120,
                title: "Created",
                format: "{0:yyyy-MM-dd}"
            }, {
                command: ["destroy"], title: "", width: 120
            }
        ],
  
        pageable: true,
        scrollable: true,
        editable: true,
        navigatable: true,
        sortable: true,
  
        dataSource: src
        //dataSource: {
        //    transport: {
        //        read: {
        //            url: "Handlers/TaskHandler.ashx",
        //            dataType: "json",
        //            type: "GET",
        //        },
        //        update: {
        //            url: "Handlers/TaskHandler.ashx",
        //            dataType: "json",
        //            type: "PUT",
        //        },
        //        destroy: {
        //            url: "Handlers/TaskHandler.ashx",
        //            dataType: "json",
        //            type: "DELETE",
        //        },
        //        create: {
        //            url: "Handlers/TaskHandler.ashx",
        //            dataType: "json",
        //            type: "POST",
        //        },
        //        parameterMap: function (options, operation) {
        //            if (operation !== "read" && options.models) {
        //                return { tasks: kendo.stringify(options.models) };
        //            }
        //        }
        //    },
  
        //    batch: true,
  
        //    schema: {
        //        model: {
        //            id: "Id",
        //            fields: {
        //                Id: { editable: false, nullable: true },
        //                Description: { type: "string", editable: true },
        //                IsComplete: { type: "boolean", editable: true },
        //                Priority: { type: "number", editable: true },
        //                CreatedOn: { type: "date", editable: false, defaultValue: new Date() }
        //            }
        //        }
        //    },
        //}
    });
});
0
Shea
Top achievements
Rank 1
answered on 26 Apr 2013, 07:01 PM
I consider pageSize to be part of my view parameters not model...
Weird, but works. 

Thanks.
Tags
Grid
Asked by
Shea
Top achievements
Rank 1
Answers by
HUA
Top achievements
Rank 1
Shea
Top achievements
Rank 1
Share this question
or