/// <summary> /// assume that tihs data comes from business layer. /// </summary> /// <param name="queryString"></param> /// <returns></returns> private DataGridResponseViewModel GetResponse(DataGridRequestQueryString queryString) { DataGridResponseViewModel model = new DataGridResponseViewModel(queryString); List <SimplePersonViewModel> pList = new List <SimplePersonViewModel>(); SimplePersonViewModel p = new SimplePersonViewModel(); for (int i = 0; i < 100; i++) { p = new SimplePersonViewModel() { Salary = i + 10.5, Name = "My name is " + (i + 1), Gender = "E", Id = i, BirthDate = DateTime.Now.AddDays(-1000 + i).ToShortDateString(), ModifiedDate = DateTime.Now.AddDays(-2000 + i).ToShortDateString(), }; pList.Add(p); } model.data = pList.Skip(queryString.start).Take(queryString.length).ToList(); model.recordsTotal = pList.Count; return(model); }
/// <summary> /// assume that tihs data comes from business layer. /// </summary> /// <param name="queryString"></param> /// <returns></returns> private DataGridResponseViewModel GetResponse(DataGridRequestQueryString queryString, int rideWith) { DataGridResponseViewModel model = new DataGridResponseViewModel(queryString); model.recordsTotal = rideWith; model.data = new CustomerDataGenerator().GenerateCustomerList(queryString, rideWith); return(model); }
/// <summary> /// xhr method that works with dataTables.js server side table /// </summary> /// <param name="queryString"></param> /// <returns></returns> public ActionResult FillDataGrid(DataGridRequestQueryString queryString) { var resp = new DataGridResponseViewModel(queryString) { // data = new CustomerDataGenerator().GenerateCustomerList(queryString), }; return(Json(resp, JsonRequestBehavior.AllowGet)); }
public ActionResult FillGrid(DataGridRequestQueryString queryString, int rideWith) { DataGridResponseViewModel resp = GetResponse(queryString, rideWith); return(Json(resp, JsonRequestBehavior.AllowGet)); }
public List <CustomerModel> GenerateCustomerList(DataGridRequestQueryString queryString, int rideWith) { DataGridOrderType orderType = queryString.orderBy == "asc" ? DataGridOrderType.Asc : DataGridOrderType.Desc; if (HttpContext.Current.Session["customers"] != null) { var list = HttpContext.Current.Session["customers"] as List <CustomerModel>; if (list.Count == rideWith) { var sortedList = Sort(list, queryString.orderedColumnName, orderType); return(sortedList.Skip(queryString.start).Take(queryString.length).ToList()); } } var customerList = new List <CustomerModel>(); #region Generate sample data FirstNameList = new List <string>(); FirstNameList.Add("Mustafa"); FirstNameList.Add("Ali"); FirstNameList.Add("Veli"); FirstNameList.Add("Hakkı"); FirstNameList.Add("Siraç"); FirstNameList.Add("Veli"); FirstNameList.Add("Muhammed"); FirstNameList.Add("Cetin"); FirstNameList.Add("Kadir"); FirstNameList.Add("Serap"); FirstNameList.Add("Selin"); FirstNameList.Add("Mehtap"); FirstNameList.Add("Dursun"); FirstNameList.Add("Selami"); FirstNameList.Add("Yavuz"); LastNameList = new List <string>(); LastNameList.Add("Korkmaz"); LastNameList.Add("Kayak"); LastNameList.Add("Yılmaz"); LastNameList.Add("Gönenç"); LastNameList.Add("Türkoglu"); LastNameList.Add("Eskir"); LastNameList.Add("Kose"); LastNameList.Add("Solmaz"); LastNameList.Add("Turhanlı"); LastNameList.Add("Tavlı"); LastNameList.Add("Bozkurt"); LastNameList.Add("Yıldırım"); LastNameList.Add("Tatar"); LastNameList.Add("Kırkıl"); LastNameList.Add("Cetin"); PositionList = new List <string>(); PositionList.Add("Müdür"); PositionList.Add("Yönetici"); PositionList.Add("Uzman"); PositionList.Add("Yetkili"); PositionList.Add("Tasarımcı"); PositionList.Add("CEO"); PositionList.Add("CFO"); OfficeList = new List <string>(); OfficeList.Add("Soma"); OfficeList.Add("Kırkagac"); OfficeList.Add("Akhisar"); OfficeList.Add("Salihli"); OfficeList.Add("Demirci"); OfficeList.Add("Alaşehir"); OfficeList.Add("Saruhanlı"); OfficeList.Add("Golmarmara"); StartDateList = new List <DateTime>(); for (int i = 0; i < 20; i++) { StartDateList.Add(DateTime.Now.AddDays((i + 1) * (-10))); } SalaryList = new List <decimal>(); Random random = new Random(); for (int i = 0; i < 20; i++) { var d = random.NextDouble() * (500 - 100) + 100; SalaryList.Add(Convert.ToDecimal(Math.Round(d, 2))); } for (int i = 0; i < rideWith; i++) { var firstName = FirstNameList[random.Next(0, 14)]; var lastName = LastNameList[random.Next(0, 14)]; var position = PositionList[random.Next(0, 6)]; var office = OfficeList[random.Next(0, 7)]; var startDate = StartDateList[random.Next(0, 19)].ToShortDateString(); var salary = SalaryList[random.Next(0, 19)]; customerList.Add(new CustomerModel { FirstName = firstName, LastName = lastName, Position = position, Office = office, Salary = salary, StartDate = startDate }); } #endregion Generate sample data HttpContext.Current.Session["customers"] = customerList; // use session as sample customer database to get always same data set in paging var customerQuery = Sort(customerList, queryString.orderedColumnName, orderType); return(customerQuery.Skip(queryString.start).Take(queryString.length).ToList()); }