title: Asp.NET How to filter a table with multiple simultaneous filters, filter it in the back-end or in the front-end?
body: <p>In my ASP.NET MVC project i have a table in the view with records from the database such as this:</p>
  
  <pre><code>&lt;div class="myWrapperClass"&gt;
  
              &lt;div class="tableContainer"&gt;
                  &lt;table class="myTableClass" id="tblOpenTickets"&gt;
                      &lt;thead&gt;
                          &lt;tr&gt;
                              &lt;th width="10%"&gt;Date&lt;/th&gt;
                              &lt;th width="5%"&gt;ID&lt;/th&gt;
                              &lt;th width="5%"&gt;Priority&lt;/th&gt;
                              &lt;th width="10%"&gt;Reporter&lt;/th&gt;
                              &lt;th width="20%"&gt;Details&lt;/th&gt;
                              &lt;th width="15%"&gt;Category&lt;/th&gt;
                              &lt;th width="15%"&gt;Tags&lt;/th&gt;
                              &lt;th width="20%"&gt;Assigned&lt;/th&gt;       
                              &lt;th&gt;Status&lt;/th&gt;
                          &lt;/tr&gt;
                      &lt;/thead&gt;
  
                      &lt;tbody&gt;
                          @foreach (Ticket tm in Model.Tickets)
                          {
                              &lt;tr class="tableRows"&gt;
                                  &lt;td data-info="Date" class="dateCell"&gt;@(tm.CreateDate.HasValue ? tm.CreateDate.Value.ToString("dd-MMM-yyyy") : "-")&lt;/td&gt;
                                  &lt;td data-info="ID" class="idsCell"&gt;@tm.ID&lt;/td&gt;
                                  &lt;td data-info="Priority" class="prioriyCell"&gt;
                                      &lt;div class="priorityContainer"&gt;
                                          &lt;span class="prioritySpan"&gt;@(!string.IsNullOrEmpty(tm.Priority) ? tm.Priority : "-")&lt;/span&gt;
                                      &lt;/div&gt;
                                  &lt;/td&gt;
                                  &lt;td data-info="Reporter"&gt;@(!string.IsNullOrEmpty(tm.Reporter) ? tm.Reporter : "-")&lt;/td&gt;
  
                                  &lt;td data-info="Details" class="detailsCell"&gt;
                                      &lt;div class="detailsContainer"&gt;
                                          &lt;span class="subjectSpan"&gt;@(!string.IsNullOrEmpty(tm.Subject) ? tm.Subject : "-")&lt;/span&gt;
                                          &lt;span class="descSpan"&gt;@(!string.IsNullOrEmpty(tm.Description) ? tm.Description : "-")&lt;/span&gt;
                                      &lt;/div&gt;
                                  &lt;/td&gt;
  
                                  @{
                                      var categoryName = Model.TicketCategories.Where(x =&gt; x.ID == tm.CategoryID).Select(x =&gt; x.Name).FirstOrDefault();
                                      &lt;td data-info="Category" class="categoryCell"&gt;@(string.IsNullOrEmpty(categoryName) ? "-" : categoryName)&lt;/td&gt;
                                  }
                                  &lt;td data-info="Tags" class="tagsCell"&gt;@(!string.IsNullOrEmpty(tm.Tags) ? tm.Tags : "-")&lt;/td&gt;
                                  &lt;td data-info="Assigned" class="assignedCell"&gt;@(!string.IsNullOrEmpty(tm.AssignedAdminsStr) ? tm.AssignedAdminsStr : "Unassigned")&lt;/td&gt;
                                  &lt;td data-info="Status" class="statusCell"&gt;@(!string.IsNullOrEmpty(tm.Status) ? tm.Status : "-")&lt;/td&gt;
                              &lt;/tr&gt;
                          }
                      &lt;/tbody&gt;
                  &lt;/table&gt;
              &lt;/div&gt;
  
              &lt;div class="cover-bar"&gt;&lt;/div&gt;
          &lt;/div&gt;
  </code></pre>
  
  <p>On the same page i have a modal that pop ups with filters to apply, which is a form then I submit the form with filters and in the controller:</p>
  
  <pre><code>{ 
  // ...... 
  ChatVM chatVM = new ChatVM();
  
  var openTixFilters = Request["hasSubmittedOpenTixFilters"];
              var closedTixFilters = Request["hasSubmittedClosedTixFilters"];
              chatVM.HasOpenTixFilters = !string.IsNullOrEmpty(openTixFilters) &amp;&amp; (openTixFilters == "true");
              chatVM.HasClosedTixFilters = !string.IsNullOrEmpty(closedTixFilters) &amp;&amp; (closedTixFilters == "true");
  
              if (chatVM.HasOpenTixFilters || chatVM.HasClosedTixFilters)
              {
                  IEnumerable&lt;Ticket&gt; filteredList = Enumerable.Empty&lt;Ticket&gt;();
                  filteredList = chatVM.HasOpenTixFilters ? chatVM.AllOpenTickets : chatVM.AllClosedTickets;
  
                  string dateStart = Request["startDate"];
                  string dateEnd = Request["endDate"];
                  string priority = Request["filterPriority"];
                  string reporter = Request["filterReporter"];
                  string category = Request["filterCategory"];
                  string assigned = Request["filterAssigned"];
                  string tags = Request["filterTags"];
                  string status = Request["filterStatus"];
                  string campus = Request["filterCampus"];
  
                  if (!string.IsNullOrEmpty(dateStart) &amp;&amp; !string.IsNullOrEmpty(dateEnd))
                  {
                      if (DateTime.TryParse(dateStart, out DateTime startDate) &amp;&amp; DateTime.TryParse(dateEnd, out DateTime endDate))
                      {
                          chatVM.HasRangeFilterApplied = true;
  
                          if (filteredList != null &amp;&amp; filteredList.Count() &gt; 0)
                              filteredList = filteredList.Where(x =&gt; x.CreateDate &gt;= startDate &amp;&amp; x.CreateDate &lt;= endDate).Select(x =&gt; x);
                      }                  
                  }
  
                  if (!string.IsNullOrEmpty(priority))
                  {
                      chatVM.HasPriorityFilterApplied = true;
                      filteredList = filteredList.Where(x =&gt; (x.Priority != null) &amp;&amp; (x.Priority.ToLower() == priority.ToLower())).Select(x =&gt; x);
                  }
  
                  if (!string.IsNullOrEmpty(reporter))
                  {
                      // To do
                  }
  
                  chatVM.TableTickets = filteredList;
              }
  
              return View(chatVM);
  }
  </code></pre>
  
  <p>I am filtering the table in the backend and re-populating with the filtered list when returning the view. I am also keeping track of the filtered applied with bools in the view model, to apply them on the view until removed. Is this a bad practice or should this filtering take place in the view as opposed to the back end? What is the best way to do this?</p>