예제 #1
0
        public JsonResult GetPeopleWithServersideFiltering([Kendo.Mvc.UI.DataSourceRequest] Kendo.Mvc.UI.DataSourceRequest request)
        {
            int totalNumberOfItems;
            IEnumerable<Person> result;

            string orderByClause = new KendoSortBuilder().CreateString(request.Sorts, "FirstName asc").CleanString();

            KendoFilterBuilder b = new KendoFilterBuilder();
            FilterDto kendoFilter = b.AssessFilters(request.Filters).BuildDynamicLinqQuery();

            if (kendoFilter.IsFilterApplying)
            {
                totalNumberOfItems = People.Where(kendoFilter.DynamicLinqString, kendoFilter.Parameters).Count();
                result = People.OrderBy(orderByClause).Where(kendoFilter.DynamicLinqString, kendoFilter.Parameters).Skip((request.Page - 1) * request.PageSize).Take(request.PageSize);
            }
            else
            {
                totalNumberOfItems = People.Count();
                result = People.OrderBy(orderByClause).Skip((request.Page - 1) * request.PageSize).Take(request.PageSize);
            }

            return Json(new { data = result, total = totalNumberOfItems }, JsonRequestBehavior.AllowGet);
        }
예제 #2
0
        public JsonResult GetPeopleWithServersideSorting([Kendo.Mvc.UI.DataSourceRequest] Kendo.Mvc.UI.DataSourceRequest request)
        {
            // the order string to pass to Dynamic LINQ
            string orderByClause = new KendoSortBuilder().CreateString(request.Sorts, "FirstName asc").CleanString();

            // the implementation of server side pagination
            var result = People.OrderBy(orderByClause).Skip((request.Page - 1) * request.PageSize).Take(request.PageSize);
            var totalNumberOfItems = People.Count();

            return Json(new { data = result, total = totalNumberOfItems }, JsonRequestBehavior.AllowGet);
        }