Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Controller JS
- $scope.mainGridOptions = {
- dataSource: {
- schema: {
- data: "Data",
- total: "Total"
- },
- transport: {
- read: function (e) {//You can get the current page, pageSize etc off `e`.
- var requestData = {
- page: e.data.page,
- pageSize: e.data.pageSize,
- type: "hello"
- };
- console.log(e);
- $http({ method: 'POST', url: 'http://localhost:9619/Home/DataSourceResult', data: requestData }).
- success(function (data, status, headers, config) {
- e.success(data);
- //console.log(data.Data);
- }).
- error(function (data, status, headers, config) {
- alert('something went wrong');
- console.log(status);
- });
- }
- },
- pageSize: 1,
- serverPaging: true,
- serverSorting: true
- },
- selectable: "row",
- pageable: true,
- sortable: true,
- groupable: true
- }
- Controller MVC
- [HttpPost]
- [AllowAnonymous]
- public ActionResult DataSourceResult(int page, string type, int pageSize)
- {
- ResponseData resultData = new ResponseData();
- string tempData = "";
- if (page == 1)
- {
- tempData = "[{\"NAME\": \"Example Name 1\", \"DESCRIPTION\": \"Example Description 1\"},{\"NAME\": \"Example Name 2\",\"DESCRIPTION\": null}]";
- }
- else if (page == 2)
- {
- tempData = "[{\"NAME\": \"Example Name 3\", \"DESCRIPTION\": \"Example Description 3\"},{\"NAME\": \"Example Name 4\",\"DESCRIPTION\": \"Example Description 4\"}]";
- }
- resultData.Data = tempData;
- resultData.Total = "2";
- string json = JsonConvert.SerializeObject(resultData);
- json = json.Replace(@"\", "");
- json = json.Replace("\"[{", "[{");
- json = json.Replace("}]\"", "}]");
- return Content(json, "application/json");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement