Skip to content

Commit 560395f

Browse files
committed
float support for individual column filtering added
1 parent 05d6cd9 commit 560395f

File tree

5 files changed

+54
-2
lines changed

5 files changed

+54
-2
lines changed

src/JQDT/DataProcessing/ColumnsFilterDataProcessing/ColumnsFilterDataProcessor.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ protected override IQueryable<T> OnProcessData(IQueryable<T> data, RequestInfoMo
7373
{
7474
currentPredicateExpr = this.rangeOrEqualsExpressionBuilder.BuildExpression(modelParam, column.Data, new FilterModel { Type = FilterTypes.eq, Value = column.Search.Value });
7575
}
76+
else
77+
{
78+
throw new ArgumentException($"Not supported type {propType} for column individual filtering.");
79+
}
7680

7781
predicateExpressions.Add(currentPredicateExpr);
7882
}

src/JQDT/Extensions/TypeExtensions.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,15 @@ internal static class TypeExptensions
6363
typeof(ulong),
6464
typeof(ulong?),
6565

66+
typeof(decimal),
67+
typeof(decimal?),
68+
6669
typeof(double),
6770
typeof(double?),
6871

72+
typeof(float),
73+
typeof(float?),
74+
6975
typeof(short),
7076
typeof(short?),
7177
typeof(ushort),
@@ -79,6 +85,9 @@ internal static class TypeExptensions
7985
typeof(char),
8086
typeof(char?),
8187

88+
typeof(bool),
89+
typeof(bool?),
90+
8291
typeof(DateTime),
8392
typeof(DateTime?),
8493
typeof(DateTimeOffset),
@@ -186,6 +195,16 @@ internal static bool IsValidForOperation(this Type type, OperationTypesEnum oper
186195
}
187196
}
188197

198+
if (operationTypes.HasFlag(OperationTypesEnum.Equals))
199+
{
200+
var isEqualValidType = supportedEqualOperationTypes.Contains(type);
201+
if (!isEqualValidType)
202+
{
203+
return false;
204+
}
205+
}
206+
207+
189208
return true;
190209
}
191210
}

src/Tests/UnitTests/Tests.UnitTests/ColumnsFilterDataProcessorTests.cs renamed to src/Tests/UnitTests/Tests.UnitTests/ColumnsFilterDataProcessorUnitTests.cs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
using TestData.Models;
1313
using Tests.UnitTests.Common;
1414

15-
internal class ColumnsFilterDataProcessorTests
15+
internal class ColumnsFilterDataProcessorUnitTests
1616
{
1717
// TODO: Add case "Filter by more than one columns"
1818

@@ -75,6 +75,8 @@ public void ColumnFilter_ShouldReturnUntouchedDataIfNoColumnFilters()
7575
[TestCase("SByteProperty", null)]
7676
[TestCase("SByteNullable", null)]
7777
[TestCase("DoubleProperty", null)]
78+
[TestCase(nameof(AllTypesModel.Float), null)]
79+
[TestCase(nameof(AllTypesModel.FloatNullable), null)]
7880
[TestCase("DoubleNullable", null)]
7981
[TestCase("DecimalProperty", null)]
8082
[TestCase("DecimalProperty", "79228162514264337593543950335")]
@@ -156,5 +158,29 @@ public void ColumnFilter_ShouldWorkAppropriateWithNestedNullableDateTime()
156158
Assert.IsTrue(processedData.All(x => x.NestedModel.DateTimeNullable.HasValue && x.NestedModel.DateTimeNullable.ToString().ToLower() == searchValue.ToLower()));
157159
Trace.WriteLine(nameof(ColumnFilter_ShouldWorkAppropriateWithAllSupportedTypesNoNestedProperties) + $" number of items: {processedData.Count} case: {column} / {searchValue}");
158160
}
161+
162+
[Test]
163+
public void ColumnFilter_ShouldThrowIfUnsupportedType()
164+
{
165+
Assert.Throws<ArgumentException>(() =>
166+
{
167+
var data = DataGenerator.GenerateSimpleData(1000);
168+
var column = "NestedModel";
169+
170+
var searchValue = "123";
171+
172+
var requestModel = TestHelpers.GetSimpleRequestInfoModel();
173+
requestModel.TableParameters.Columns = new List<Column>
174+
{
175+
new Column{ Data = column, Search = new Search{ Value = searchValue } }
176+
};
177+
178+
var processedData = this.filterSimpleModelProcessor.ProcessData(data, requestModel).ToList();
179+
180+
Assert.IsTrue(processedData.All(x => x.NestedModel.DateTimeNullable.HasValue && x.NestedModel.DateTimeNullable.ToString().ToLower() == searchValue.ToLower()));
181+
Trace.WriteLine(nameof(ColumnFilter_ShouldWorkAppropriateWithAllSupportedTypesNoNestedProperties) + $" number of items: {processedData.Count} case: {column} / {searchValue}");
182+
183+
});
184+
}
159185
}
160186
}

src/Tests/UnitTests/Tests.UnitTests/Tests.UnitTests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
</Reference>
6767
</ItemGroup>
6868
<ItemGroup>
69-
<Compile Include="ColumnsFilterDataProcessorTests.cs" />
69+
<Compile Include="ColumnsFilterDataProcessorUnitTests.cs" />
7070
<Compile Include="Common\TestHelpers.cs" />
7171
<Compile Include="CustomFiltersDataProcessorTests.cs" />
7272
<Compile Include="PagingDataProcessorTests.cs" />

src/jQueryDT.sln

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ Global
5757
{C82E4675-88AB-4B78-8475-F1521BDAE330}.Release|Any CPU.ActiveCfg = Release|Any CPU
5858
{C82E4675-88AB-4B78-8475-F1521BDAE330}.Release|Any CPU.Build.0 = Release|Any CPU
5959
{C82E4675-88AB-4B78-8475-F1521BDAE330}.TEST_SQL|Any CPU.ActiveCfg = TEST_SQL|Any CPU
60+
{C82E4675-88AB-4B78-8475-F1521BDAE330}.TEST_SQL|Any CPU.Build.0 = TEST_SQL|Any CPU
6061
{F7F12DE8-F3C3-42A4-BBE4-1868D287D388}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
6162
{F7F12DE8-F3C3-42A4-BBE4-1868D287D388}.Debug|Any CPU.Build.0 = Debug|Any CPU
6263
{F7F12DE8-F3C3-42A4-BBE4-1868D287D388}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -97,10 +98,12 @@ Global
9798
{D845AB6D-1887-4597-9256-148AD0A11459}.Release|Any CPU.ActiveCfg = Release|Any CPU
9899
{D845AB6D-1887-4597-9256-148AD0A11459}.Release|Any CPU.Build.0 = Release|Any CPU
99100
{D845AB6D-1887-4597-9256-148AD0A11459}.TEST_SQL|Any CPU.ActiveCfg = TEST_SQL|Any CPU
101+
{D845AB6D-1887-4597-9256-148AD0A11459}.TEST_SQL|Any CPU.Build.0 = TEST_SQL|Any CPU
100102
{A57F2EDC-8DC9-4A9A-BD3D-5CA31EE56910}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
101103
{A57F2EDC-8DC9-4A9A-BD3D-5CA31EE56910}.Release|Any CPU.ActiveCfg = Release|Any CPU
102104
{A57F2EDC-8DC9-4A9A-BD3D-5CA31EE56910}.Release|Any CPU.Build.0 = Release|Any CPU
103105
{A57F2EDC-8DC9-4A9A-BD3D-5CA31EE56910}.TEST_SQL|Any CPU.ActiveCfg = TEST_SQL|Any CPU
106+
{A57F2EDC-8DC9-4A9A-BD3D-5CA31EE56910}.TEST_SQL|Any CPU.Build.0 = TEST_SQL|Any CPU
104107
{51C58242-648E-4B17-A249-F2C844743A1B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
105108
{51C58242-648E-4B17-A249-F2C844743A1B}.Debug|Any CPU.Build.0 = Debug|Any CPU
106109
{51C58242-648E-4B17-A249-F2C844743A1B}.Release|Any CPU.ActiveCfg = Release|Any CPU

0 commit comments

Comments
 (0)