Skip to content

Commit d6ba473

Browse files
committed
Update DataTablesFiltering.cs
Fixed an issue when filtering on a data table throws an exception in cases there are no relevant columns to be filtered. Example: data table contains only numerical columns and a user types 'a letter'. Since the letter cannot be converted to a number, no where clause is generated and data.Where command was failing.
1 parent c4101d3 commit d6ba473

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

Mvc.JQuery.DataTables.Common/DataTablesFiltering.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ public IQueryable<T> ApplyFiltersAndSort<T>(DataTablesParam dtParameters, IQuery
3030
}
3131
}
3232
var values = parts.Where(p => p != null);
33-
data = data.Where(string.Join(" or ", values), parameters.ToArray());
33+
var filterClause = string.Join(" or ", values);
34+
if (string.IsNullOrWhiteSpace(filterClause) == false)
35+
{
36+
data = data.Where(filterClause, parameters.ToArray());
37+
}
3438
}
3539
for (int i = 0; i < dtParameters.sSearchValues.Count; i++)
3640
{

0 commit comments

Comments
 (0)