Advertisement
aboalkhair

Kendo Grid server-side-paging-with-angularjs

Mar 2nd, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.69 KB | None | 0 0
  1. Controller JS
  2.  
  3. $scope.mainGridOptions = {
  4. dataSource: {
  5. schema: {
  6. data: "Data",
  7. total: "Total"
  8. },
  9. transport: {
  10. read: function (e) {//You can get the current page, pageSize etc off `e`.
  11. var requestData = {
  12. page: e.data.page,
  13. pageSize: e.data.pageSize,
  14. type: "hello"
  15. };
  16. console.log(e);
  17. $http({ method: 'POST', url: 'http://localhost:9619/Home/DataSourceResult', data: requestData }).
  18. success(function (data, status, headers, config) {
  19. e.success(data);
  20. //console.log(data.Data);
  21. }).
  22. error(function (data, status, headers, config) {
  23. alert('something went wrong');
  24. console.log(status);
  25. });
  26. }
  27. },
  28. pageSize: 1,
  29. serverPaging: true,
  30. serverSorting: true
  31. },
  32. selectable: "row",
  33. pageable: true,
  34. sortable: true,
  35. groupable: true
  36. }
  37.  
  38.  
  39.  
  40.  
  41. Controller MVC
  42.  
  43. [HttpPost]
  44. [AllowAnonymous]
  45. public ActionResult DataSourceResult(int page, string type, int pageSize)
  46. {
  47. ResponseData resultData = new ResponseData();
  48. string tempData = "";
  49. if (page == 1)
  50. {
  51. tempData = "[{\"NAME\": \"Example Name 1\", \"DESCRIPTION\": \"Example Description 1\"},{\"NAME\": \"Example Name 2\",\"DESCRIPTION\": null}]";
  52. }
  53. else if (page == 2)
  54. {
  55. tempData = "[{\"NAME\": \"Example Name 3\", \"DESCRIPTION\": \"Example Description 3\"},{\"NAME\": \"Example Name 4\",\"DESCRIPTION\": \"Example Description 4\"}]";
  56. }
  57. resultData.Data = tempData;
  58. resultData.Total = "2";
  59. string json = JsonConvert.SerializeObject(resultData);
  60. json = json.Replace(@"\", "");
  61. json = json.Replace("\"[{", "[{");
  62. json = json.Replace("}]\"", "}]");
  63. return Content(json, "application/json");
  64. }
  65.  
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement