Hi Team
I have logic that does not filter out my search well, i am using dataTable and its using server side processing to retrieve data to my table from the database. I do have few records with data, but they dont filter at all. Please view my logic and help produce results better, thanks.
- // Controller class
- [HttpPost]
- public ActionResult GetList()
- {
- //Server side Parameter.
- int start = Convert.ToInt32(Request["start"]);
- int length = Convert.ToInt32(Request["length"]);
- string searchValue = Request["search[value]"];
- string sortColumnName = Request["columns[" + Request["order[0][column]"] + "][name]"];
- string sortDirection = Request["order[0][dir]"];
- List
empList = new List (); - using (eNtsaOnlineRegistrationDBContext db = new eNtsaOnlineRegistrationDBContext())
- {
- empList = db.TblEventsManagements.ToList
(); - int totalrows = empList.Count();
- if (!string.IsNullOrEmpty(searchValue))
- {
- empList = empList.Where(x => x.TrainingType.ToLower().Contains(searchValue.ToLower()) || x.TrainingDescription.ToLower().Contains(searchValue.ToLower()) || x.Price.ToString().Contains(searchValue.ToLower())
- || x.Venue.ToLower().Contains(searchValue.ToLower()) || x.Facilitator.ToLower().Contains(searchValue.ToLower()) || x.WhoAttend.ToLower().Contains(searchValue.ToLower()) || x.Rsvp.ToLower().Contains(searchValue.ToLower())).ToList
(); - }
- int totalrowsafterfiltering = empList.Count;
- empList = empList.OrderBy(sortColumnName + " " + sortDirection).ToList
(); - empList = empList.Skip(start).Take(length).ToList
(); - return Json(new { data = empList, draw = Request["draw"], recordsTotal = totalrows, recordsFiltered = totalrowsafterfiltering }, JsonRequestBehavior.AllowGet);
- }
- }
- // View cshtml
- @{
- ViewBag.Title = "EventManagement List";
- }
EventManagement List
"EventManagementTable" class="ui celled table" style="width:100%">
- @*Semantic UI*@
- @*
"EventManagementTable" class="ui celled table">*@
- @*Bootstrap*@
- @*
"EventManagementTable" class="table table-striped table-bordered">*@
TrainingType TrainingDescription Price Venue Facilitator WhoAttend RSVP TrainingType TrainingDescription Price Venue Facilitator WhoAttend RSVP - "//cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.6/semantic.min.css" rel="stylesheet" />
- "https://cdn.datatables.net/1.10.15/css/dataTables.semanticui.min.css" rel="stylesheet" />
- @section scripts{
- }
1 Reply
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Laxmidhar SahooPosted Feb 13, 2020, 10:39 PM