Ejemplo n.º 1
0
        // for display datatable
        public ActionResult GetCategoryList(DataTablesRequest param)
        {
            //http://www.justinmichaels.net/using-jquery-datatables-with-asp-net-mvc-for-serverside-filtering-sorting-and-paging
            var categoryList = _db.Categories.AsEnumerable();

            var viewCategoryList = categoryList;

            IEnumerable <Category> filteredCategoryList;

            if (!string.IsNullOrEmpty(param.sSearch))
            {
                filteredCategoryList = viewCategoryList.Where(cat => (cat.Name ?? "").Contains(param.sSearch)).ToList();
            }
            else
            {
                filteredCategoryList = viewCategoryList;
            }

            var viewDataList = filteredCategoryList.Skip(param.iDisplayStart).Take(param.iDisplayLength).ToList();

            string[] data = viewDataList.ConvertAll(x => x.ToString()).ToArray();

            var result = DataTablesResponse.CreateResponse(param, categoryList.Count(), filteredCategoryList.Count(), data);

            return(Json(result, JsonRequestBehavior.AllowGet));
        }