Skip to content

Commit f0b8c25

Browse files
Merge pull request #5 from fouadgm/feature/net-core-31
.NET Core 3.1, EF LINQ performance, Library updates
2 parents a80d4b7 + 0ebc321 commit f0b8c25

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+8764
-2277
lines changed

src/jQueryDatatableServerSideNetCore/Controllers/TestRegistersController.cs

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ public async Task<IActionResult> LoadTable([FromBody]DtParameters dtParameters)
3333
{
3434
var searchBy = dtParameters.Search?.Value;
3535

36-
var orderCriteria = string.Empty;
36+
// if we have an empty search then just order the results by Id ascending
37+
var orderCriteria = "Id";
3738
var orderAscendingDirection = true;
3839

3940
if (dtParameters.Order != null)
@@ -42,14 +43,8 @@ public async Task<IActionResult> LoadTable([FromBody]DtParameters dtParameters)
4243
orderCriteria = dtParameters.Columns[dtParameters.Order[0].Column].Data;
4344
orderAscendingDirection = dtParameters.Order[0].Dir.ToString().ToLower() == "asc";
4445
}
45-
else
46-
{
47-
// if we have an empty search then just order the results by Id ascending
48-
orderCriteria = "Id";
49-
orderAscendingDirection = true;
50-
}
5146

52-
var result = await _context.TestRegisters.ToListAsync();
47+
var result = _context.TestRegisters.AsQueryable();
5348

5449
if (!string.IsNullOrEmpty(searchBy))
5550
{
@@ -60,25 +55,24 @@ public async Task<IActionResult> LoadTable([FromBody]DtParameters dtParameters)
6055
r.Phone != null && r.Phone.ToUpper().Contains(searchBy.ToUpper()) ||
6156
r.ZipCode != null && r.ZipCode.ToUpper().Contains(searchBy.ToUpper()) ||
6257
r.Country != null && r.Country.ToUpper().Contains(searchBy.ToUpper()) ||
63-
r.Notes != null && r.Notes.ToUpper().Contains(searchBy.ToUpper()))
64-
.ToList();
58+
r.Notes != null && r.Notes.ToUpper().Contains(searchBy.ToUpper()));
6559
}
6660

67-
result = orderAscendingDirection ? result.AsQueryable().OrderByDynamic(orderCriteria, DtOrderDir.Asc).ToList() : result.AsQueryable().OrderByDynamic(orderCriteria, DtOrderDir.Desc).ToList();
61+
result = orderAscendingDirection ? result.OrderByDynamic(orderCriteria, DtOrderDir.Asc) : result.OrderByDynamic(orderCriteria, DtOrderDir.Desc);
6862

6963
// now just get the count of items (without the skip and take) - eg how many could be returned with filtering
70-
var filteredResultsCount = result.Count();
64+
var filteredResultsCount = await result.CountAsync();
7165
var totalResultsCount = await _context.TestRegisters.CountAsync();
7266

73-
return Json(new
67+
return Json(new DtResult<TestRegister>
7468
{
75-
draw = dtParameters.Draw,
76-
recordsTotal = totalResultsCount,
77-
recordsFiltered = filteredResultsCount,
78-
data = result
69+
Draw = dtParameters.Draw,
70+
RecordsTotal = totalResultsCount,
71+
RecordsFiltered = filteredResultsCount,
72+
Data = await result
7973
.Skip(dtParameters.Start)
8074
.Take(dtParameters.Length)
81-
.ToList()
75+
.ToListAsync()
8276
});
8377
}
8478

src/jQueryDatatableServerSideNetCore/Models/AuxiliaryModels/DatatableModels.cs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,18 @@ public class DtResult<T>
3333
/// <summary>
3434
/// The data to be displayed in the table.
3535
/// This is an array of data source objects, one for each row, which will be used by DataTables.
36-
/// Note that this parameter's name can be changed using the ajaxDT option's dataSrc property.
36+
/// Note that this parameter's name can be changed using the ajax option's dataSrc property.
3737
/// </summary>
3838
[JsonProperty("data")]
3939
public IEnumerable<T> Data { get; set; }
4040

41+
/// <summary>
42+
/// Optional: If an error occurs during the running of the server-side processing script, you can inform the user of this error by passing back the error message to be displayed using this parameter.
43+
/// Do not include if there is no error.
44+
/// </summary>
45+
[JsonProperty("error", NullValueHandling = NullValueHandling.Ignore)]
46+
public string Error { get; set; }
47+
4148
public string PartialView { get; set; }
4249
}
4350

@@ -59,11 +66,19 @@ public abstract class DtRow
5966
public virtual string DtRowClass => null;
6067

6168
/// <summary>
62-
/// Add this data property to the row's dt-tag tr node allowing abstract data to be added to the node, using the HTML5 data-* attributes.
63-
/// This uses the jQuery data() method to set the data, which can also then be used for later retrieval (for example on a click event).
69+
/// Add the data contained in the object to the row using the jQuery data() method to set the data, which can also then be used for later retrieval (for example on a click event).
6470
/// </summary>
6571
[JsonProperty("DT_RowData")]
6672
public virtual object DtRowData => null;
73+
74+
/// <summary>
75+
/// Add the data contained in the object to the row dt-tag tr node as attributes.
76+
/// The object keys are used as the attribute keys and the values as the corresponding attribute values.
77+
/// This is performed using using the jQuery param() method.
78+
/// Please note that this option requires DataTables 1.10.5 or newer.
79+
/// </summary>
80+
[JsonProperty("DT_RowAttr")]
81+
public virtual object DtRowAttr => null;
6782
}
6883

6984
/// <summary>
@@ -147,7 +162,7 @@ public class DtColumn
147162
public bool Orderable { get; set; }
148163

149164
/// <summary>
150-
/// Specific search value.
165+
/// Search value to apply to this specific column.
151166
/// </summary>
152167
public DtSearch Search { get; set; }
153168
}

src/jQueryDatatableServerSideNetCore/jQueryDatatableServerSideNetCore.csproj

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp3.0</TargetFramework>
4+
<TargetFramework>netcoreapp3.1</TargetFramework>
55
<UserSecretsId>aspnet-jQueryDatatableServerSideNetCore-F30D421D-7C39-47E7-8247-3E3BE3C0B128</UserSecretsId>
66
</PropertyGroup>
77

88

99
<ItemGroup>
10-
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="3.0.3" />
11-
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="3.0.3" />
12-
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="3.0.3" />
13-
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.0.3" />
14-
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.0.3" />
15-
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.0.3" />
10+
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="3.1.6" />
11+
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="3.1.6" />
12+
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="3.1.6" />
13+
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.6" />
14+
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.6" />
15+
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.6">
16+
<PrivateAssets>all</PrivateAssets>
17+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
18+
</PackageReference>
1619
<PackageReference Include="RandomGen" Version="1.1.4" />
1720
</ItemGroup>
1821

src/jQueryDatatableServerSideNetCore/wwwroot/lib/bootstrap/LICENSE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2011-2018 Twitter, Inc.
4-
Copyright (c) 2011-2018 The Bootstrap Authors
3+
Copyright (c) 2011-2020 Twitter, Inc.
4+
Copyright (c) 2011-2020 The Bootstrap Authors
55

66
Permission is hereby granted, free of charge, to any person obtaining a copy
77
of this software and associated documentation files (the "Software"), to deal

src/jQueryDatatableServerSideNetCore/wwwroot/lib/bootstrap/dist/css/bootstrap-grid.css

Lines changed: 8 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/jQueryDatatableServerSideNetCore/wwwroot/lib/bootstrap/dist/css/bootstrap-grid.css.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/jQueryDatatableServerSideNetCore/wwwroot/lib/bootstrap/dist/css/bootstrap-grid.min.css

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/jQueryDatatableServerSideNetCore/wwwroot/lib/bootstrap/dist/css/bootstrap-grid.min.css.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/jQueryDatatableServerSideNetCore/wwwroot/lib/bootstrap/dist/css/bootstrap-reboot.css

Lines changed: 8 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/jQueryDatatableServerSideNetCore/wwwroot/lib/bootstrap/dist/css/bootstrap-reboot.css.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)