Skip to content
Permalink
Browse files

Add column filtering (non-arrays only atm)

  • Loading branch information...
Marlamin committed Sep 7, 2019
1 parent 95f9e2b commit 083b8ee8525f00e985a40b2dabc2e27ff74b6443
Showing with 30 additions and 5 deletions.
  1. +30 −5 DBCDumpHost/Controllers/DataController.cs
@@ -52,7 +52,7 @@ public DataTablesResult Get(string name, string build, int draw, int start, int
else
{
searching = true;
Logger.WriteLine("Serving data " + start + "," + length + " for dbc " + name + " (" + build + ") for draw " + draw + " with filter " + searchValue);
Logger.WriteLine("Serving data " + start + "," + length + " for dbc " + name + " (" + build + ") for draw " + draw + " with search " + searchValue);
}

var result = new DataTablesResult
@@ -73,6 +73,20 @@ public DataTablesResult Get(string name, string build, int draw, int start, int

result.data = new List<List<string>>();

var filtering = false;
var filters = new Dictionary<int, string>();

// this is gonna break for tables with arrays
for (var i = 0; i < storage.AvailableColumns.Length; ++i)
{
if (Request.Query.ContainsKey("columns[" + i + "][search][value]") && !string.IsNullOrWhiteSpace(Request.Query["columns[" + i + "][search][value]"]))
{
searching = true;
filtering = true;
filters.Add(i, Request.Query["columns[" + i + "][search][value]"]);
}
}

var resultCount = 0;
foreach (DBCDRow item in storage.Values)
{
@@ -90,8 +104,11 @@ public DataTablesResult Get(string name, string build, int draw, int start, int
var val = a.GetValue(j).ToString();
if (searching)
{
if (val.Contains(searchValue, StringComparison.InvariantCultureIgnoreCase))
matches = true;
if (!filtering)
{
if (val.Contains(searchValue, StringComparison.InvariantCultureIgnoreCase))
matches = true;
}
}

val = System.Web.HttpUtility.HtmlEncode(val);
@@ -104,8 +121,16 @@ public DataTablesResult Get(string name, string build, int draw, int start, int
var val = field.ToString();
if (searching)
{
if (val.Contains(searchValue, StringComparison.InvariantCultureIgnoreCase))
matches = true;
if (filtering)
{
if(filters.ContainsKey(i) && filters[i] == val)
matches = true;
}
else
{
if (val.Contains(searchValue, StringComparison.InvariantCultureIgnoreCase))
matches = true;
}
}

val = System.Web.HttpUtility.HtmlEncode(val);

0 comments on commit 083b8ee

Please sign in to comment.
You can’t perform that action at this time.