This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@model List<string> | |
@using System.Text | |
@section Styles { | |
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.css"> | |
} | |
@{ | |
var tableHeader = new StringBuilder(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[HttpPost] | |
public IActionResult GetPeopleData(DataParameters parameters) | |
{ | |
var items = personService.GetPeopleForDataTable(parameters); | |
var dataTable = DataTableHelper.BuildDataTable(items.Data, items.Count); | |
dataTable.Draw = parameters.Draw; | |
return Ok(dataTable); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public IActionResult Index() | |
{ | |
ViewData["Title"] = "Home Page"; | |
var header = DataTableHelper.BuildDataTableHeader(new PersonTableViewModel()); | |
return View(header); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function () { | |
$("#table-list").DataTable({ | |
"processing": true, | |
"serverSide": true, | |
"ajax": { | |
type: "POST", | |
url: "home/getpeopledata" | |
} | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using ReportsWeb.Attributes; | |
using ReportsWeb.Models.DataTable; | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Net; | |
using System.Reflection; | |
namespace ReportsWeb.Helpers | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public (IEnumerable<PersonTableViewModel> Data, int Count) GetPeopleForDataTable(DataParameters parameters) | |
{ | |
var items = personRepository.GetPeopleReadOnly() | |
.Select(x => new PersonTableViewModel | |
{ | |
FullName = x.FullName, | |
PreferredName = x.PreferredName, | |
Phone = x.Phone, | |
Email = x.Email, | |
Age = (DateTime.Now.Subtract(x.DateOfBirth).Days / 365).ToString(), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Newtonsoft.Json; | |
using System.Collections.Generic; | |
namespace ReportsWeb.Models.DataTable | |
{ | |
public class TableViewModel | |
{ | |
[JsonProperty(PropertyName = "draw")] | |
public int Draw { get; set; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using ReportsWeb.Attributes; | |
using ReportsWeb.Helpers; | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Linq.Expressions; | |
using System.Reflection; | |
namespace ReportsWeb.Models.DataTable | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Newtonsoft.Json; | |
using System.Collections.Generic; | |
namespace ReportsWeb.Models.DataTable | |
{ | |
public sealed class DataParameters | |
{ | |
[JsonProperty(PropertyName = "draw")] | |
public int Draw { get; set; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using ReportsWeb.Models; | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
namespace ReportsWeb.Repository | |
{ | |
public sealed class PersonRepository | |
{ | |
public IEnumerable<Person> GetPeopleReadOnly() |
NewerOlder