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 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions01ForumsTop experts
Arun PottiAnswers in the forums20answers02
Tahir AnsariAnswers in the forums5answers03
Kamlesh KumarAnswers in the forums5answers04
Sam HobbsAnswers in the forums4answers05
Željko PerićAnswers in the forums3answersFull leaderboard →
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Laxmidhar SahooRank #383 · 6.6K reputationPosted Feb 13, 2020, 5:39 PM EST