title: C# ASP MVC5 Datatable Individual Search column how to filter && and ||
body: <p><strong>Trying to achieve</strong></p>
  
  <p>I have managed to pass the values of all the individual columns to <code>server</code> using <code>AjaxGet</code>. In the following, <code>pic</code> or example would be <code>t</code> and <code>v</code>. 
  At the server, I will pass the value to a <code>filter</code> method. Now, I am trying to figure out how to properly filter <code>t</code> and <code>v</code>.
  Currently, after <code>v</code> is inputted, I will filter <code>v</code> and then if <code>t</code> is inputted, ideally it should filter <code>t</code> for <code>LOGIN_ID</code> column and <code>v</code> for <code>NAME</code> column. However, I am getting <code>v</code> or <code>t</code> results. Please help. </p>
  
  <p><a href="https://i.stack.imgur.com/DTMtI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DTMtI.png" alt="enter image description here"></a></p>
  
  <p><strong>CODE</strong></p>
  
  <pre><code>private List&lt;DataItem&gt; FilterData(ref int recordFiltered, int start, int length, string search, string searchLOGIN_ID, string searchNAME, string searchDT_EDIT, int sortColumn, string sortDirection)
  
      {
          List&lt;DataItem&gt; _data = CreateData();
  
          List&lt;DataItem&gt; list = new List&lt;DataItem&gt;();
  
          if (!string.IsNullOrEmpty(searchLOGIN_ID))
          {
              foreach (DataItem dataItem in _data)
              {
                  if (
                      dataItem.LOGIN_ID.ToUpper().Contains(searchLOGIN_ID.ToUpper())
                      )
                  {
                      list.Add(dataItem);
                  }
              }
          }
  
          if (!string.IsNullOrEmpty(searchNAME))
          {
              foreach (DataItem dataItem in _data)
              {
                  if (
                      dataItem.NAME.ToUpper().Contains(searchNAME.ToUpper())
                      )
                  {
                      list.Add(dataItem);
                  }
              }
          }
  
          if (!string.IsNullOrEmpty(searchDT_EDIT))
          {
              foreach (DataItem dataItem in _data)
              {
                  if (
                      dataItem.DT_EDIT.ToUpper().Contains(searchDT_EDIT.ToUpper())
                      )
                  {
                      list.Add(dataItem);
                  }
              }
          }
  
          if (!string.IsNullOrEmpty(searchLOGIN_ID) &amp;&amp; !string.IsNullOrEmpty(searchNAME) &amp;&amp; !string.IsNullOrEmpty(searchDT_EDIT))
          {
              foreach (DataItem dataItem in _data)
              {
                  if (
                      dataItem.LOGIN_ID.ToUpper().Contains(search.ToUpper()) ||
                      dataItem.NAME.ToString().Contains(search.ToUpper()) ||
                      dataItem.DT_EDIT.ToString().Contains(search.ToUpper())
                      )
                  {
                      list.Add(dataItem);
                  }
              }
          }
  
          if (!string.IsNullOrEmpty(searchLOGIN_ID) &amp;&amp; !string.IsNullOrEmpty(searchNAME))
          {
              foreach (DataItem dataItem in _data)
              {
                  if (
                      dataItem.LOGIN_ID.ToUpper().Contains(searchLOGIN_ID.ToUpper()) ||
                      dataItem.NAME.ToUpper().Contains(searchNAME.ToUpper())
                      )
                  {
                      list.Add(dataItem);
                  }
              }
          }
  
          if (!string.IsNullOrEmpty(searchLOGIN_ID) &amp;&amp; !string.IsNullOrEmpty(searchDT_EDIT))
          {
              foreach (DataItem dataItem in _data)
              {
                  if (
                      dataItem.LOGIN_ID.ToUpper().Contains(searchLOGIN_ID.ToUpper()) ||
                      dataItem.DT_EDIT.ToUpper().Contains(searchDT_EDIT.ToUpper())
                      )
                  {
                      list.Add(dataItem);
                  }
              }
          }
  
          if (!string.IsNullOrEmpty(searchNAME) &amp;&amp; !string.IsNullOrEmpty(searchDT_EDIT))
          {
  
              foreach (DataItem dataItem in _data)
              {
                  if (
                      dataItem.NAME.ToUpper().Contains(searchNAME.ToUpper()) ||
                      dataItem.DT_EDIT.ToUpper().Contains(searchDT_EDIT.ToUpper())
                      )
                  {
                      list.Add(dataItem);
                  }
              }
          }
  
          if (!string.IsNullOrEmpty(search))
          {
              foreach (DataItem dataItem in _data)
              {
                  if (
                      dataItem.LOGIN_ID.ToUpper().Contains(search.ToUpper()) ||
                      dataItem.NAME.ToString().Contains(search.ToUpper()) ||
                      dataItem.DT_EDIT.ToString().Contains(search.ToUpper())
                      )
                  {
                      list.Add(dataItem);
                  }
              }
          }
  
          if(string.IsNullOrEmpty(search) &amp;&amp; string.IsNullOrEmpty(searchLOGIN_ID) &amp;&amp; string.IsNullOrEmpty(searchNAME) &amp;&amp; string.IsNullOrEmpty(searchDT_EDIT))
          {
              list = _data;
          }
  
          // simulate sort
          //=== sortColumn need to change additional column
          if (sortColumn == 1)
          {   // sort LOGIN_ID
              list.Sort((x, y) =&gt; SortString(x.LOGIN_ID, y.LOGIN_ID, sortDirection));
          }
          else if (sortColumn == 2)
          {   // sort NAME
              list.Sort((x, y) =&gt; SortString(x.NAME, y.NAME, sortDirection));
          }
          else if (sortColumn == 3)
          {   // sort DT_CREATE
              list.Sort((x, y) =&gt; SortDateTime(x.DT_EDIT, y.DT_EDIT, sortDirection));
          }
  
          recordFiltered = list.Count;
  
          // get just one page of data
          list = list.GetRange(start, Math.Min(length, list.Count - start));
  
          return list;
      }
  
  public ActionResult AjaxGetJsonData(int draw, int start, int length)
      {
          var searchLOGIN_ID = Request.QueryString["columns[1][search][value]"];
          var searchNAME = Request.QueryString["columns[2][search][value]"];
          var searchDT_EDIT = Request.QueryString["columns[3][search][value]"];
          string search = Request.QueryString["search[value]"];
  
          int sortColumn = -1;
          string sortDirection = "asc";
          if (length == -1)
          {
              length = TOTAL_ROWS;
          }
          if (Request.QueryString["order[0][column]"] != null)
          {
              sortColumn = int.Parse(Request.QueryString["order[0][column]"]);
          }
          if (Request.QueryString["order[0][dir]"] != null)
          {
              sortDirection = Request.QueryString["order[0][dir]"];
          }
  
          DataTableData dataTableData = new DataTableData();
          dataTableData.draw = draw;
          dataTableData.recordsTotal = TOTAL_ROWS;
          int recordsFiltered = 0;
          dataTableData.data = FilterData(ref recordsFiltered, start, length, search, searchLOGIN_ID, searchNAME, searchDT_EDIT, sortColumn, sortDirection);
          dataTableData.recordsFiltered = recordsFiltered;
  
          return Json(dataTableData, JsonRequestBehavior.AllowGet);
      }
  </code></pre>
  
  <p><strong>GITHUB</strong></p>
  
  <p><a href="https://github.com/BROMVC5/BROSTANDARD" rel="nofollow noreferrer">https://github.com/BROMVC5/BROSTANDARD</a></p>