With the newest version of Kendo UI (now in Beta), there is another way that we can implement server-side swapping using the $http.post Angular method provides a Kendo table read function.
This is an example of using MVC 5 as an endpoint for data that you receive from a data source. It simulates a server swap by sending page and pageSize to the controller, you can also send take and skip , if necessary, and process it as you like.
HTML markup
<div ng-controller="MyCtrl"> <kendo-grid k-options="mainGridOptions"></kendo-grid> </div>
Javascript
function MyCtrl($scope, $http) { $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: '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 } }
You can get the current pageSize, page, accept, skip, and more from the e argument in the read: function(e){} declaration.
Because post values ββrefer to arguments from the read function, they are updated every time the page is refreshed in the grid. This is what you can use to update your message values ββevery time the grid makes changes. Then the mesh is re-linked.
Home / DataSourceResult Controller
[HttpPost] 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 = "4"; string json = JsonConvert.SerializeObject(resultData); json = json.Replace(@"\", ""); json = json.Replace("\"[{", "[{"); json = json.Replace("}]\"", "}]"); return Content(json, "application/json"); }
Very simple, but exactly what I need and can help you. This uses the built-in Angular http.get function, but allows the Kendo grid to do most of your heavy lifting.