Skip to content

Commit 46141de

Browse files
committed
Added default checkbox filter for true/false
1 parent 4f4e991 commit 46141de

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

Mvc.JQuery.Datatables.Example/Controllers/HomeController.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ public DataTablesResult<UserView> GetUsers(DataTablesParam dataTableParam)
3737
Email = user.Email,
3838
Position = user.Position == null ? "" : user.Position.ToString(),
3939
Number = user.Number,
40-
Hired = user.Hired
40+
Hired = user.Hired,
41+
IsAdmin = user.IsAdmin
4142
});
4243
}
4344

@@ -52,7 +53,6 @@ private static List<User> Users()
5253
{
5354
var r = new Random();
5455
var domains = "gmail.com,yahoo.com,hotmail.com".Split(',').ToArray();
55-
5656
var positions = new List<PositionTypes?> { null, PositionTypes.Engineer, PositionTypes.Tester, PositionTypes.Manager };
5757
return _users ?? (_users = new List<User>
5858
(
@@ -63,6 +63,7 @@ private static List<User> Users()
6363
Email = "user" + i + "@" + domains[i%domains.Length],
6464
Name = r.Next(6) == 3 ? null : "User" + i,
6565
Position = positions[i%positions.Count],
66+
IsAdmin = i % 11 == 0,
6667
Number = (Numbers) r.Next(4),
6768
Hired = DateTimeOffset.UtcNow.AddDays(-1 * 365 * 3 * r.NextDouble())
6869
})
@@ -89,7 +90,9 @@ public class User
8990

9091
public DateTimeOffset Hired { get; set; }
9192

92-
public Numbers Number { get; set; }
93+
public Numbers Number { get; set; }
94+
95+
public bool IsAdmin { get; set; }
9396
}
9497

9598
public class UserView
@@ -99,8 +102,8 @@ public class UserView
99102
[DisplayName("Full Name")]
100103
public MvcHtmlString Name { get; set; }
101104

102-
public string Email { get; set; }
103-
105+
public string Email { get; set; }
106+
public bool IsAdmin { get; set; }
104107
public string Position { get; set; }
105108
public DateTimeOffset Hired { get; set; }
106109

Mvc.JQuery.Datatables.Example/Mvc.JQuery.Datatables.Example.csproj

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
<UpgradeBackupLocation>
2222
</UpgradeBackupLocation>
2323
<OldToolsVersion>4.0</OldToolsVersion>
24+
<IISExpressSSLPort />
25+
<IISExpressAnonymousAuthentication />
26+
<IISExpressWindowsAuthentication />
27+
<IISExpressUseClassicPipelineMode />
2428
</PropertyGroup>
2529
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
2630
<DebugSymbols>true</DebugSymbols>
@@ -262,7 +266,7 @@
262266
<WebProjectProperties>
263267
<UseIIS>False</UseIIS>
264268
<AutoAssignPort>True</AutoAssignPort>
265-
<DevelopmentServerPort>50564</DevelopmentServerPort>
269+
<DevelopmentServerPort>49660</DevelopmentServerPort>
266270
<DevelopmentServerVPath>/</DevelopmentServerVPath>
267271
<IISUrl>
268272
</IISUrl>

Mvc.JQuery.Datatables/DataTableVm.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ public string GetFilterType(string columnName, Type type)
8686
public static FilterRuleList StaticFilterTypeRules = new FilterRuleList()
8787
{
8888
(c, t) => (DateTypes.Contains(t)) ? "{type: 'date-range'}" : null,
89+
(c, t) => t == typeof(bool) ? "{type: 'checkbox', values : ['True', 'False']}" : null,
8990
(c, t) => "{type: 'text'}", //by default, text filter on everything
9091
};
9192

0 commit comments

Comments
 (0)