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