Skip to content

Instantly share code, notes, and snippets.

🤓
Coding

Davidson Sousa davidsonsousa

🤓
Coding
Block or report user

Report or block davidsonsousa

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View Index.cshtml
@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();
View GetPeopleData_method.cs
[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);
}
View Index_method.cs
public IActionResult Index()
{
ViewData["Title"] = "Home Page";
var header = DataTableHelper.BuildDataTableHeader(new PersonTableViewModel());
return View(header);
}
View index.js
$(document).ready(function () {
$("#table-list").DataTable({
"processing": true,
"serverSide": true,
"ajax": {
type: "POST",
url: "home/getpeopledata"
}
});
});
View DataTableHelper.cs
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
{
View GetPeopleForDataTable_method.cs
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(),
View TableViewModel.cs
using Newtonsoft.Json;
using System.Collections.Generic;
namespace ReportsWeb.Models.DataTable
{
public class TableViewModel
{
[JsonProperty(PropertyName = "draw")]
public int Draw { get; set; }
View PersonTableViewModel.cs
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
{
View DataParameters.cs
using Newtonsoft.Json;
using System.Collections.Generic;
namespace ReportsWeb.Models.DataTable
{
public sealed class DataParameters
{
[JsonProperty(PropertyName = "draw")]
public int Draw { get; set; }
View PersonRepository.cs
using ReportsWeb.Models;
using System;
using System.Collections.Generic;
using System.Linq;
namespace ReportsWeb.Repository
{
public sealed class PersonRepository
{
public IEnumerable<Person> GetPeopleReadOnly()
You can’t perform that action at this time.