Gcobani Mkontwana

Gcobani Mkontwana

  • 1.4k
  • 516
  • 16.2k

empty record list on your Jquery dataTable

Feb 13 2020 12:42 AM
Hi Team
 
I am returning an empty record list on my dataTable, what could be an issue? Is the issue on my calling of dbContext not correcttly? Please help me mates as i am returning an empty record list on UI. Here is my logic below for this reason.
  1. [HttpPost]  
  2. public ActionResult GetList() {  
  3.  //Server side Parameter.    
  4.  int start = Convert.ToInt32(Request["start"]);  
  5.  int length = Convert.ToInt32(Request["length"]);  
  6.  string searchValue = Request["search[value]"];  
  7.  string sortColumnName = Request["columns[" + Request["order[0][column]"] + "][name]"];  
  8.  string sortDirection = Request["order[0][dir]"];  
  9.  using(eNtsaOnlineRegistrationDBContext db = new eNtsaOnlineRegistrationDBContext()) {  
  10.   IQueryable < TblEventsManagements > empList = db.TblEventsManagements;  
  11.   int totalrows = empList.Count();  
  12.   int totalrowsafterfiltering = totalrows;  
  13.   
  14.   if (!string.IsNullOrEmpty(searchValue)) {  
  15.    empList = empList.Where(x => x.TrainingType.Contains(searchValue) || x.TrainingDescription.Contains(searchValue) || x.Price.ToString().Contains(searchValue.ToLower()) ||  
  16.     x.Venue.Contains(searchValue) || x.Facilitator.Contains(searchValue) || x.WhoAttend.Contains(searchValue) || x.Rsvp.Contains(searchValue));  
  17.    totalrowsafterfiltering = empList.Count();  
  18.   }  
  19.   empList = empList.OrderBy(sortColumnName + " " + sortDirection).Skip(start).Take(length);  
  20.   
  21.   return Json(new {  
  22.    data = empList.ToList(), draw = Request["draw"], recordsTotal = totalrows, recordsFiltered = totalrowsafterfiltering  
  23.   }, JsonRequestBehavior.AllowGet);  
  24.  }  
  25. }  
  1. <script>    
  2.         $(document).ready(function () {    
  3.                $("#EventsManagementsTable").DataTable({    
  4.                 "ajax": {    
  5.                     "url""/Dashboard/GetList",    
  6.                     "type""POST",    
  7.                     "datatype":"json"    
  8.                 },    
  9.                    "columns": [    
  10.                     {"data""TrainingType""name""TrainingType"},    
  11.                     { "data""TrainingDescription""name""TrainingDescription" },    
  12.                     { "data""Price""name""Price" },    
  13.                     { "data""Venue""name""Venue" },    
  14.                     { "data""Facilitator""name""Facilitator" },    
  15.                     { "data""WhoAttend""name""WhoAttend" },    
  16.                     {"data""RSVP""name""RSVP"},    
  17.                 ],    
  18.                     
  19.                 "serverSide""true",    
  20.                 "order":[0,"asc"],    
  21.                 "processing""true",    
  22.                 "language": {    
  23.                     "processing":"processing... please wait"    
  24.                 }  
  25.             });  
  26.         });  
  27. </script> 

Answers (9)