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

Kendo Grid paging - how to on server side

2 Answers 403 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 19 Aug 2015, 08:07 PM

I have a standard task of showing remote data in the grid with paging enabled( user test data is a 100 rows). 

My question is that I don't understand how to properly return the data. My current version just displays 5 records and that's it.

Following is my grid setup in the controller. 

$scope.grdUsers = {

        dataSource: {
            schema: {
                model: {
                    fields: {
                        userid:     { type: "number" },
                        FullName:   { type: "string" },
                        username:   { type: "string" },
                        email:      { type: "string" }
                    }
                }
            },
            transport: {
                type: 'json',
                read: function (e) {
                    var requestData = {
                        page: e.data.page,
                        pageSize: e.data.pageSize,
                        what: 'wa_users',
                        tstamp: (new Date()).getTime()
                    };
                    $http({ method: 'POST', url: './waOpps.ashx',  params: requestData }).
                    success(function (data, status, headers, config) {
                        e.success(data);
                    }).
                    error(function (data, status, headers, config) {
                    });
                }
            },
            pageSize: 5,
            filterable: true,
            serverPaging: true,
            serverSorting: true
        },
        selectable: "row",
        pageable: true,
        sortable: true,
        columns: [
            {
                field: "FullName",
                title: "Name",
            },
            {
                field: "username",
                title: "username",
            },
            {
                field: "email",
                title: "email"
            }
        ]
    };

 

My server side is:

class tmpuser
        {
            public Int32 userid;
            public String FullName;
            public String username;
            public String email;
            public tmpuser(Int32 uid)
            {
                userid = uid;
                FullName = String.Format("fullname {0}",userid);
                username = String.Format("username {0}", userid);
                email = String.Format("email {0}", userid);
            }
        };


        private void getusers(HttpContext context)
        {
            Int32 page = Convert.ToInt32(context.Request["page"]);
            Int32 pageSize = Convert.ToInt32(context.Request["pageSize"]);
            Int32 startIndex = (page - 1) * pageSize;
            List<tmpuser> lst = new List<tmpuser>();
            for (int i = startIndex; i < Math.Min(startIndex + pageSize, 100); ++i) 
                lst.Add(new tmpuser(i));
            String v = JsonConvert.SerializeObject(lst);
            context.Response.Write(v);
        }‚Äč

2 Answers, 1 is accepted

Sort by
0
Michael
Top achievements
Rank 1
answered on 19 Aug 2015, 10:08 PM

Solved for paging. Next issue is how to implement sorting.

Schema is changed to:

schema: {
                data: 'GridData',
                total: 'TotalCount',
                model: {...

 

And server returns json for the class with GridData and TotalCount members

0
Viktor Tachev
Telerik team
answered on 20 Aug 2015, 03:22 PM
Hello Michael,

When you enable the serverSorting option for the dataSource the sorting operation will be performed on the server by default. Check out the following article that describes the feature in more detail.



Regards,
Viktor Tachev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Grid
Asked by
Michael
Top achievements
Rank 1
Answers by
Michael
Top achievements
Rank 1
Viktor Tachev
Telerik team
Share this question
or