Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added improvements #50

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion AspNetCoreWeb/AspNetCoreWeb.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<PackageReference Include="Microsoft.AspNetCore.Mvc.Localization" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Razor" Version="2.2.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="System.Text.Json" Version="4.7.1" />
<PackageReference Include="System.Text.Json" Version="4.7.2" />
<None Include="Images\icon.png" Pack="true" PackagePath="" />
<None Include="..\LICENSE.md" Pack="true" PackagePath="" />
</ItemGroup>
Expand Down
49 changes: 49 additions & 0 deletions AspNetCoreWeb/Extentions/DataTableExtentions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using JqueryDataTables.ServerSide.AspNetCoreWeb.Models;
using Newtonsoft.Json;
using System.Collections.Generic;
using System.Linq;

namespace JqueryDataTables.ServerSide.AspNetCoreWeb.Extentions
{
/// <summary>
/// Extention Methods to convert data table result from list
/// </summary>
public static class DataTableExtentions
{
public static JqueryDataTablesResult<T> ToDataTable<T>(this IEnumerable<T> list, int draw, int totalCount, int filteredCount)
{
return new JqueryDataTablesResult<T>
{
Data = list,
Draw = draw,
RecordsFiltered = filteredCount,
RecordsTotal = totalCount
};
}
public static JqueryDataTablesResult<T> ToDataTable<T>(this IEnumerable<T> list, int draw, int totalCount)
{
return new JqueryDataTablesResult<T>
{
Data = list,
Draw = draw,
RecordsFiltered = list.Count(),
RecordsTotal = totalCount
};
}
public static JqueryDataTablesResult<T> ToDataTable<T>(this IEnumerable<T> list, int draw)
{
return new JqueryDataTablesResult<T>
{
Data = list,
Draw = draw,
RecordsFiltered = list.Count(),
RecordsTotal = list.Count()
};
}
public static string ToJsonString<T>(this JqueryDataTablesResult<T> result)
{
var json = JsonConvert.SerializeObject(result);
return json;
}
}
}
12 changes: 4 additions & 8 deletions AspNetCoreWeb/Models/JqueryDataTablesModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,27 @@ public class JqueryDataTablesResult<T>
/// The draw counter that this object is a response to - from the draw parameter sent as part of the data request.
/// Note that it is strongly recommended for security reasons that you cast this parameter to an integer, rather than simply echoing back to the client what it sent in the draw parameter, in order to prevent Cross Site Scripting (XSS) attacks.
/// </summary>
[JsonProperty(PropertyName = "draw")]
[JsonPropertyName("draw")]
[JsonProperty("draw")]
public int Draw { get; set; }

/// <summary>
/// Total records, before filtering (i.e. the total number of records in the database)
/// </summary>
[JsonProperty(PropertyName = "recordsTotal")]
[JsonPropertyName("recordsTotal")]
[JsonProperty("recordsTotal")]
public int RecordsTotal { get; set; }

/// <summary>
/// Total records, after filtering (i.e. the total number of records after filtering has been applied - not just the number of records being returned for this page of data).
/// </summary>
[JsonProperty(PropertyName = "recordsFiltered")]
[JsonPropertyName("recordsFiltered")]
[JsonProperty("recordsFiltered")]
public int RecordsFiltered { get; set; }

/// <summary>
/// The data to be displayed in the table.
/// This is an array of data source objects, one for each row, which will be used by DataTables.
/// Note that this parameter's name can be changed using the ajaxDT option's dataSrc property.
/// </summary>
[JsonProperty(PropertyName = "data")]
[JsonPropertyName("data")]
[JsonProperty("data")]
public IEnumerable<T> Data { get; set; }
}

Expand Down
2 changes: 1 addition & 1 deletion AspNetCoreWeb/Models/JqueryDataTablesPagedResults{T}.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace JqueryDataTables.ServerSide.AspNetCoreWeb.Models
{
public class JqueryDataTablesPagedResults<T>
public class JqueryDataTablesResults<T>
{
public IEnumerable<T> Items { get; set; }

Expand Down