-
Notifications
You must be signed in to change notification settings - Fork 149
/
Copy pathFacetController.cs
62 lines (52 loc) · 2.33 KB
/
FacetController.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using Microsoft.AspNetCore.Mvc;
using Mvc.JQuery.DataTables.Example.Domain;
using System;
using System.Linq;
namespace Mvc.JQuery.DataTables.Example.Controllers
{
public class FacetController : Controller
{
public IActionResult Index()
{
return View();
}
public DataTablesResult<UserFacetRowViewModel> GetFacetedUsers(DataTablesParam dataTableParam)
{
return DataTablesResult.Create(FakeDatabase.Users.Select(user => new UserFacetRowViewModel()
{
Email = user.Email,
Position = user.Position == null ? "" : user.Position.ToString(),
Hired = user.Hired,
IsAdmin = user.IsAdmin,
Content = "https://randomuser.me/api/portraits/thumb/men/" + user.Id + ".jpg"
}), dataTableParam,
rowViewModel => new
{
Content = "<div>" +
" <div>Email: " + rowViewModel.Email + (rowViewModel.IsAdmin ? " (admin)" : "") + "</div>" +
" <div>Hired: " + rowViewModel.Hired + "</div>" +
" <img src='" + rowViewModel.Content + "' />" +
"</div>"
});
}
public class UserFacetRowViewModel
{
[DataTables(DisplayName = "E-Mail", Searchable = true, Visible = false)]
[DataTablesFilter(Selector = "#" + nameof(Email) + "Filter")]
public string Email { get; set; }
[DataTables(Width = "70px", Visible = false)]
[DataTablesFilter(Selector = "#" +nameof(IsAdmin) + "Filter")]
public bool IsAdmin { get; set; }
[DataTables(Width = "70px", Visible = false)]
[DataTablesFilter(Selector = "#" + nameof(Position) + "Filter")]
public string Position { get; set; }
[DataTablesFilter(DataTablesFilterType.DateTimeRange, Selector = "#" + nameof(Hired) + "Filter")]
[DefaultToStartOf2014]
[DataTables(Visible = false)]
public DateTime? Hired { get; set; }
[DataTables(Sortable = false, Searchable = false)]
[DataTablesFilter(DataTablesFilterType.None)]
public string Content { get; set; }
}
}
}