示例#1
0
        public int countCustomers(GridSettings gridSettings)
        {
            var customers = dataContext.Customers.AsQueryable();

            if (gridSettings.IsSearch)
            {
                foreach (var rule in gridSettings.Where.rules)
                {
                    customers = filterCustomers(customers, rule);
                }
            }
            return customers.Count();
        }
示例#2
0
        public IQueryable<Customer> getCustomers(GridSettings gridSettings)
        {
            var customers = orderCustomers(dataContext.Customers.AsQueryable(), gridSettings.SortColumn, gridSettings.SortOrder);

            if (gridSettings.IsSearch)
            {
                foreach (var rule in gridSettings.Where.rules)
                {
                    customers = filterCustomers(customers, rule);
                }
            }

             return customers.Skip((gridSettings.PageIndex - 1) * gridSettings.PageSize).Take(gridSettings.PageSize);
        }
示例#3
0
        /// <summary>
        /// AJAX request, retrieves data for basic grid
        /// </summary>
        /// <param name="gridSettings">Settings received from jqGrid request</param>
        /// <returns>JSON view containing data for basic grid</returns>
        public ActionResult GridDataBasic(GridSettings gridSettings)
        {
            var customers = this.repo.getCustomers(gridSettings);
            int totalCustomers = this.repo.countCustomers(gridSettings);

            var jsonData = new
            {
                total = totalCustomers / gridSettings.PageSize + 1,
                page = gridSettings.PageIndex,
                records = totalCustomers,
                rows = (
                    from c in customers
                    select new { id = c.CustomerID, cell = new string[] {
                                                                            c.CustomerID.ToString(),
                                                                            string.Format("{0} {1}", c.FirstName, c.LastName),
                                                                            c.CompanyName,
                                                                            c.EmailAddress,
                                                                            c.ModifiedDate.ToShortDateString(),
                                                                            c.Phone
                                                                        }}).ToArray()
            };

            return Json(jsonData, JsonRequestBehavior.AllowGet);
        }